Skip to content

Commit

Permalink
Merge commit 'cca5b0eed68a420e7082da960d69435138046d38' into sachinpk…
Browse files Browse the repository at this point in the history
…ale/master
  • Loading branch information
dakrone committed Oct 26, 2017
2 parents 678b666 + cca5b0e commit becf772
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/clj_http/conn_mgr.clj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
IOReactorConfig
AbstractMultiworkerIOReactor$DefaultThreadFactory
DefaultConnectingIOReactor)
(org.apache.http.nio.conn NoopIOSessionStrategy)))
(org.apache.http.nio.conn NoopIOSessionStrategy)
(org.apache.http.nio.protocol HttpAsyncRequestExecutor)
(org.apache.http.impl.nio DefaultHttpClientIODispatch)
(org.apache.http.config ConnectionConfig)))

(def ^:private insecure-context-verifier
(delay {
Expand Down Expand Up @@ -289,9 +292,14 @@
(or keystore trust-store)
(get-keystore-scheme-registry config)

:else regular-strategy-registry)]
:else regular-strategy-registry)
io-reactor (make-ioreactor io-config)
protocol-handler (HttpAsyncRequestExecutor.)
io-event-dispatch (DefaultHttpClientIODispatch. protocol-handler
ConnectionConfig/DEFAULT)]
(future (.execute io-reactor io-event-dispatch))
(proxy [PoolingNHttpClientConnectionManager ReuseableAsyncConnectionManager]
[(make-ioreactor io-config) nil registry nil nil timeout
[io-reactor nil registry nil nil timeout
java.util.concurrent.TimeUnit/SECONDS])))

(defn ^PoolingNHttpClientConnectionManager make-reuseable-async-conn-manager
Expand Down
20 changes: 20 additions & 0 deletions test/clj_http/test/client_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -1284,6 +1284,26 @@
"connection should be closed")
(.shutdown cm)))

(deftest ^:integration t-reusable-async-conn-mgrs
(run-server)
(let [cm (conn/make-reuseable-async-conn-manager {:timeout 10 :insecure? false})
resp1 (promise) resp2 (promise)
exce1 (promise) exce2 (promise)]
(request {:async? true :uri "/redirect-to-get" :method :get :connection-manager cm}
resp1
exce1)
(request {:async? true :uri "/redirect-to-get" :method :get}
resp2
exce2)
(is (= 200 (:status @resp1) (:status @resp2)))
(is (nil? (get-in @resp1 [:headers "connection"]))
"connection should remain open")
(is (= "close" (get-in @resp2 [:headers "connection"]))
"connection should be closed")
(is (not (realized? exce2)))
(is (not (realized? exce1)))
(.shutdown cm)))

(deftest ^:integration t-with-async-pool
(run-server)
(client/with-async-connection-pool {}
Expand Down

0 comments on commit becf772

Please sign in to comment.