Skip to content

Commit

Permalink
Merge commit 'feb3c4810dfa3303d7d85dc0db30a59f08029651' into EvanHahn…
Browse files Browse the repository at this point in the history
…/override-request-config-and-context
  • Loading branch information
dakrone committed May 24, 2017
2 parents 6a6de16 + feb3c48 commit 0a70faf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/clj_http/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,8 @@
((make-proxy-method-with-body request-method) http-url)
(make-proxy-method request-method http-url))))

(defn ^HttpClientContext http-context [request-config]
(doto (HttpClientContext/create)
(defn ^HttpClientContext http-context [request-config http-client-context]
(doto (or http-client-context (HttpClientContext/create))
(.setRequestConfig request-config)))

(defn ^CredentialsProvider credentials-provider []
Expand Down Expand Up @@ -350,6 +350,7 @@
redirect-strategy max-redirects retry-handler
request-method scheme server-name server-port socket-timeout
uri response-interceptor proxy-host proxy-port async?
http-client-context http-request-config
proxy-ignore-hosts proxy-user proxy-pass digest-auth ntlm-auth]
:as req} respond raise]
(let [req (dissoc req :async?)
Expand All @@ -362,8 +363,8 @@
(get-conn-mgr async? req))
proxy-ignore-hosts (or proxy-ignore-hosts
#{"localhost" "127.0.0.1"})
^RequestConfig request-config (request-config req)
^HttpClientContext context (http-context request-config)
^RequestConfig request-config (or http-request-config (request-config req))
^HttpClientContext context (http-context request-config http-client-context)
^HttpUriRequest http-req (http-request-for
request-method http-url body)]
(when-not (conn/reusable? conn-mgr)
Expand Down
22 changes: 22 additions & 0 deletions test/clj_http/test/core_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
(org.apache.http.params CoreConnectionPNames CoreProtocolPNames)
(org.apache.http.message BasicHeader BasicHeaderIterator)
(org.apache.http.client.methods HttpPost)
(org.apache.http.client.protocol HttpClientContext)
(org.apache.http.client.config RequestConfig)
(org.apache.http.client.params CookiePolicy ClientPNames)
(org.apache.http HttpRequest HttpResponse HttpConnection
HttpInetConnection HttpVersion)
Expand Down Expand Up @@ -633,3 +635,23 @@
["http://localhost:18080/get"]))

(is (= (:trace-redirects resp-without-redirects) []))))

(deftest ^:integration t-override-request-config
(run-server)
(let [called-args (atom [])
real-http-client core/http-client
http-context (HttpClientContext/create)
request-config (.build (RequestConfig/custom))]
(with-redefs [core/http-client (fn [& args]
(proxy [org.apache.http.impl.client.CloseableHttpClient] []
(execute [http-req context]
(swap! called-args conj [http-req context])
(.execute (apply real-http-client args) http-req context))))]
(client/request {:method :get
:url "http://localhost:18080/get"
:http-client-context http-context
:http-request-config request-config})

(let [context-for-request (last (last @called-args))]
(is (= http-context context-for-request))
(is (= request-config (.getRequestConfig context-for-request)))))))

0 comments on commit 0a70faf

Please sign in to comment.