Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: dakrone/clj-http
...
head fork: dakrone/clj-http
Checking mergeability… Don't worry, you can still create the pull request.
  • 5 commits
  • 4 files changed
  • 0 commit comments
  • 2 contributors
Commits on Nov 19, 2012
@kanaka kanaka Allow requests to have multiple headers with the same name.
To make a request with multiple same named headers, use a collection
for the value.

(http/get url {:debug true :headers {"x-myheader" ["value1" "value2"]}})

...
HttpRequest:
{...
 :allHeaders
 [...
  #<BasicHeader x-myheader: value1>,
  #<BasicHeader x-myheader: value2>],
 ...}
bc65f1c
@dakrone Merge remote-tracking branch 'kanaka/master' e609e6c
@dakrone Add test for collections as headers 712ef0d
@dakrone Whitespace in core tests 56c3a8d
@dakrone Document headers as string or collection 5424c5b
View
4 Readme.md
@@ -79,6 +79,10 @@ More example requests:
:conn-timeout 1000
:accept :json})
+;; Specifying headers as either a string or collection:
+(client/get "http://example.com"
+ {:headers {"foo" ["bar" "baz"], "eggplant" "quux"}})
+
;; Set any specific client parameters manually:
(client/post "http://example.com"
{:client-params {"http.protocol.allow-circular-redirects" false
View
3  changelog.org
@@ -213,6 +213,9 @@
* Work log
Log of merges/issues/work that's gone in so I know what to put in
the changelog for the next release
+** 2012-11-19
+ - merged https://github.com/dakrone/clj-http/pull/101 to allow
+ request headers to specify multiple values
** Released 0.5.8
** 2012-11-15
- add buffering for HttpEntity, with ability to turn off if needed,
View
5 src/clj_http/core.clj
@@ -211,7 +211,10 @@
(when (instance? SingleClientConnManager conn-mgr)
(.addHeader http-req "Connection" "close"))
(doseq [[header-n header-v] headers]
- (.addHeader http-req header-n header-v))
+ (if (coll? header-v)
+ (doseq [header-vth header-v]
+ (.addHeader http-req header-n header-vth))
+ (.addHeader http-req header-n header-v)))
(if multipart
(.setEntity #^HttpEntityEnclosingRequest http-req
(mp/create-multipart-entity multipart))
View
50 test/clj_http/test/core.clj
@@ -60,7 +60,9 @@
[:move "/move"]
{:status 200 :body "move"}
[:patch "/patch"]
- {:status 200 :body "patch"}))
+ {:status 200 :body "patch"}
+ [:get "/headers"]
+ {:status 200 :body (json/encode (:headers req))}))
(defn run-server
[]
@@ -357,19 +359,19 @@
(is (every? #(instance? HttpConnection (:http-conn %)) @saved-ctx))))
(deftest ^{:integration true} t-send-input-stream-body
- (run-server)
- (let [b1 (:body (client/post "http://localhost:18080/post"
- {:body (ByteArrayInputStream. (.getBytes "foo"))
- :length 3}))
- b2 (:body (client/post "http://localhost:18080/post"
- {:body (ByteArrayInputStream.
- (.getBytes "foo"))}))
- b3 (:body (client/post "http://localhost:18080/post"
- {:body (ByteArrayInputStream. (.getBytes "apple"))
- :length 2}))]
- (is (= b1 "foo"))
- (is (= b2 "foo"))
- (is (= b3 "ap"))))
+ (run-server)
+ (let [b1 (:body (client/post "http://localhost:18080/post"
+ {:body (ByteArrayInputStream. (.getBytes "foo"))
+ :length 3}))
+ b2 (:body (client/post "http://localhost:18080/post"
+ {:body (ByteArrayInputStream.
+ (.getBytes "foo"))}))
+ b3 (:body (client/post "http://localhost:18080/post"
+ {:body (ByteArrayInputStream. (.getBytes "apple"))
+ :length 2}))]
+ (is (= b1 "foo"))
+ (is (= b2 "foo"))
+ (is (= b3 "ap"))))
(deftest t-add-client-params
(testing "Using add-client-params!"
@@ -400,13 +402,23 @@
(run-server)
(client/with-connection-pool {:threads 1}
(let [async-request #(future (client/request {:scheme :http
- :server-name "localhost"
- :server-port 18080
- :request-method :get :uri "/timeout"}))
- is-pool-timeout-error? (fn[req-fut] instance? org.apache.http.conn.ConnectionPoolTimeoutException
- (try @req-fut (catch Exception e (.getCause e))))
+ :server-name "localhost"
+ :server-port 18080
+ :request-method :get :uri "/timeout"}))
+ is-pool-timeout-error? (fn[req-fut] instance? org.apache.http.conn.ConnectionPoolTimeoutException
+ (try @req-fut (catch Exception e (.getCause e))))
req1 (async-request)
req2 (async-request)
timeout-error1 (is-pool-timeout-error? req1)
timeout-error2 (is-pool-timeout-error? req2)]
(is (or timeout-error1 timeout-error2)))))
+
+(deftest ^{:integration true} t-header-collections
+ (run-server)
+ (let [headers (-> (client/get "http://localhost:18080/headers"
+ {:headers {"foo" ["bar" "baz"]
+ "eggplant" "quux"}})
+ :body
+ json/decode)]
+ (is (= {"eggplant" "quux" "foo" "bar,baz"}
+ (select-keys headers ["foo" "eggplant"])))))

No commit comments for this range

Something went wrong with that request. Please try again.