Doesn't distinguish between a nil (meaning don't change the default) and false.
Here is the fix. It also adds the ability to configure a couple more things in the underlying library: asynchronous connection and the executor service
diff --git a/src/clj/http/async/client.clj b/src/clj/http/async/client.clj
index ca3ee1e..b4188f3 100644
--- a/src/clj/http/async/client.clj
+++ b/src/clj/http/async/client.clj
@@ -20,7 +20,8 @@
(:use [http.async.client request headers util]
clojure.template)
(:import (java.io ByteArrayOutputStream)
- (com.ning.http.client AsyncHttpClient AsyncHttpClientConfig$Builder)))
+ (com.ning.http.client AsyncHttpClient AsyncHttpClientConfig$Builder)
+ (com.ning.http.client.providers.netty NettyAsyncHttpProviderConfig)))
(defn create-client
"Creates new Async Http Client.
@@ -47,18 +48,26 @@
proxy
realm
request-timeout
- user-agent]}]
+ user-agent
+ async-connect
+ executor-service]}]
(AsyncHttpClient.
(.build
(let [b (AsyncHttpClientConfig$Builder.)]
- (when compression-enabled (.setCompressionEnabled b compression-enabled))
+ (when (not (nil? compression-enabled)) (.setCompressionEnabled b compression-enabled))
(when connection-timeout (.setConnectionTimeoutInMs b connection-timeout))
- (when follow-redirects (.setFollowRedirects b follow-redirects))
- (when idle-in-pool-timeout (.setIdleConnectionInPoolTimeoutInMs b idle-in-pool-timeout))
- (when keep-alive (.setKeepAlive b keep-alive))
+ (when (not (nil? follow-redirects)) (.setFollowRedirects b follow-redirects))
+ (when idle-in-pool-timeout (.setConnectionTimeoutInMs b idle-in-pool-timeout))
+ (when (not (nil? keep-alive)) (.setAllowPoolingConnection b keep-alive))
(when max-conns-per-host (.setMaximumConnectionsPerHost b max-conns-per-host))
(when max-conns-total (.setMaximumConnectionsTotal b max-conns-total))
(when max-redirects (.setMaximumNumberOfRedirects b max-redirects))
+ (when async-connect
+ (let [provider-config (doto (NettyAsyncHttpProviderConfig.)
+ (.removeProperty NettyAsyncHttpProviderConfig/USE_BLOCKING_IO)
+ (.addProperty NettyAsyncHttpProviderConfig/EXECUTE_ASYNC_CONNECT true))]
+ (.setAsyncHttpClientProviderConfig b provider-config)))
+ (when executor-service (.setExecutorService b executor-service))
(set-proxy proxy b)
(when realm
(set-realm realm b))
The problem is that
Doesn't distinguish between a nil (meaning don't change the default) and false.
Here is the fix. It also adds the ability to configure a couple more things in the underlying library: asynchronous connection and the executor service