Skip to content

Commit

Permalink
Merge pull request diamondap#3 from revelytix/master
Browse files Browse the repository at this point in the history
Remove dependency on clojure-contrib to make this friendlier for Clojure 1.3 use.
  • Loading branch information
A. Diamond committed Oct 11, 2011
2 parents 7a5f3f6 + 592fbb2 commit ddb1618
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 19 deletions.
9 changes: 5 additions & 4 deletions project.clj
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
(defproject diamondap/clj-apache-https "1.0.15-SNAPSHOT"
:description "Clojure HTTP library using the Apache HttpClient. Based on clj-apache-http, but includes support for SSL client certificates and HttpAsyncClient."

:dependencies [[org.clojure/clojure "1.2.0"]
[org.clojure/clojure-contrib "1.2.0"]
:dependencies [[org.clojure/clojure "1.2.1"]
[org.clojure/data.json "0.1.1"]
[org.apache.httpcomponents/httpcore "4.1.1"]
[org.apache.httpcomponents/httpmime "4.1.1"]
[commons-logging/commons-logging "1.1.1"]
[org.apache.httpcomponents/httpclient "4.1.1"]
[org.apache.httpcomponents/httpasyncclient "4.0-alpha2"]]
:dev-dependencies [[swank-clojure "1.3.0-SNAPSHOT"]]
[org.apache.httpcomponents/httpasyncclient "4.0-alpha2"]
[commons-codec "1.5"]]
:dev-dependencies [[swank-clojure "1.3.0-SNAPSHOT"]]
:repositories {"releases" ~(str "file://"
user/local-maven-clone "/releases")
"snapshots" ~(str "file://"
Expand Down
14 changes: 9 additions & 5 deletions src/com/twinql/clojure/async_client.clj
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@
StrictHostnameVerifier))
(:import (org.apache.http.impl.nio.reactor
DefaultConnectingIOReactor))
(:require [clojure.contrib.io :as io])
(:require [clojure.contrib.base64 :as base64])
(:require [clojure.contrib.string :as string])
(:import (org.apache.commons.codec.binary
Base64))
(:require [clojure.string :as string])
(:require [com.twinql.clojure.http :as http])

(:require [com.twinql.clojure.sync-libs :as sync])
Expand Down Expand Up @@ -335,7 +335,7 @@

(defn response-body [response]
"Returns the body of the response."
(io/slurp* (.. response getEntity getContent)))
(slurp (.. response getEntity getContent)))

(defn create-request
"Returns a new instance of a request of the specified method. Param method
Expand Down Expand Up @@ -374,12 +374,16 @@
(interpose "&")
(apply str))))

(def UTF8 (java.nio.charset.Charset/forName "UTF-8"))

(defn- encode-str [^String s]
(String. (Base64/encodeBase64 (.getBytes s "UTF-8") false) UTF8))

(defn get-basic-auth-value
"Returns the value of the basic auth header."
[user pwd]
(str "Basic "
(string/chomp (base64/encode-str (str user ":" pwd)))))
(string/trim-newline (encode-str (str user ":" pwd)))))


(defn add-basic-auth-header!
Expand Down
10 changes: 5 additions & 5 deletions src/com/twinql/clojure/http.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
(:refer-clojure :exclude [get])
(:use clojure.set)
(:require
[clojure.contrib.io :as io]
[clojure.contrib.json :as json])
[clojure.java.io :as io]
[clojure.data.json :as json])
(:import
(java.lang Exception)
(java.net URI)
Expand Down Expand Up @@ -205,17 +205,17 @@

(defmethod entity-as :string [#^HttpEntity entity as status]
(with-open [#^InputStream stream (.getContent entity)]
(io/slurp* stream)))
(slurp stream)))

;;; JSON handling.
;;; We prefer keywordizing.
(defmethod entity-as :json [#^HttpEntity entity as status]
(with-open [#^InputStream stream (.getContent entity)]
(clojure.contrib.json/read-json (io/reader stream) true)))
(json/read-json (io/reader stream) true)))

(defmethod entity-as :json-string-keys [#^HttpEntity entity as status]
(with-open [#^InputStream stream (.getContent entity)]
(clojure.contrib.json/read-json (io/reader stream) false)))
(json/read-json (io/reader stream) false)))


;;; To avoid overhead in shutting down a ClientConnectionManager,
Expand Down
4 changes: 2 additions & 2 deletions src/com/twinql/clojure/x509_connection_manager.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(ns com.twinql.clojure.x509-connection-manager
(:require [com.twinql.clojure.http :as http])
(:require [com.twinql.clojure.NaiveTrustManager :as trust-mgr])
(:require [clojure.contrib.java-utils :as jutil])
(:require [clojure.java.io :as io])
(:require [com.twinql.clojure.sync-libs :as sync])
(:require [com.twinql.clojure.async-libs :as async])
(:import
Expand Down Expand Up @@ -59,7 +59,7 @@
within the jar at the specified path."
[#^String path]
(try
(if (. (jutil/file path) exists)
(if (. (io/file path) exists)
(FileInputStream. path)
(load-embedded-resource path))
(catch Exception _ (throw (new FileNotFoundException
Expand Down
5 changes: 2 additions & 3 deletions tests/async_client.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
(:require [com.twinql.clojure.async-client :as async])
(:require [com.twinql.clojure.async-libs :as async-libs])
(:require [com.twinql.clojure.http :as http])
(:require [clojure.contrib.io :as io])
(:use clojure.test)
(:import
(java.net URI)))
Expand Down Expand Up @@ -113,7 +112,7 @@

;; This post has no body, but it does have query params,
;; so query params go in the body.
(io/slurp* (.. req2 getEntity getContent))
(slurp (.. req2 getEntity getContent))
"name=Edgar&age=89&weight=166&city=Boston"

;; When query params go in the body, Content-Type header
Expand All @@ -128,7 +127,7 @@
"Spongebob"

;; Be sure body was set from :body option.
(io/slurp* (.. req3 getEntity getContent))
(slurp (.. req3 getEntity getContent))
sample-body )))

;; These are some default options for the HTTP connections we want to set up.
Expand Down

0 comments on commit ddb1618

Please sign in to comment.