Permalink
Browse files

Merge pull request #96 from pgelinas/compression

Add the possibility to handle gzip, deflate content
  • Loading branch information...
helun committed Dec 6, 2012
2 parents 4fe69eb + 1356ace commit d19933f3edd099b62f8d96569e69b8cb135768e3
Showing with 28 additions and 6 deletions.
  1. +1 −0 changelog.md
  2. +26 −5 org.ektorp/src/main/java/org/ektorp/http/StdHttpClient.java
  3. +1 −1 pom.xml
View
@@ -26,6 +26,7 @@ Ektorp 1.3.0 brings support for CouchDB 1.2 and Jackson 1.9
Andreas Litt
David Venable
+* HttpClient version change to 4.2.1 to enable gzip,deflate
esromneb
@@ -29,9 +29,11 @@
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.entity.InputStreamEntity;
import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.DecompressingHttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.cache.CacheConfig;
import org.apache.http.impl.client.cache.CachingHttpClient;
+import org.apache.http.impl.conn.PoolingClientConnectionManager;
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
@@ -193,6 +195,7 @@ public void shutdown() {
boolean cleanupIdleConnections = true;
boolean useExpectContinue = true;
boolean caching = true;
+ boolean compression; // Default is false;
int maxObjectSizeBytes = 8192;
int maxCacheEntries = 1000;
@@ -241,6 +244,23 @@ public Builder proxy(String s) {
proxy = s;
return this;
}
+
+ /**
+ * Controls if the http client should send Accept-Encoding: gzip,deflate
+ * header and handle Content-Encoding responses. This enable compression
+ * on the server; although not supported natively by CouchDB, you can
+ * use a reverse proxy, such as nginx, in front of CouchDB to achieve
+ * this.
+ * <p>
+ * Disabled by default (for backward compatibility).
+ *
+ * @param b
+ * @return This builder
+ */
+ public Builder compression(boolean b){
+ compression = b;
+ return this;
+ }
/**
* Controls if the http client should cache response entities.
* Default is true.
@@ -267,7 +287,7 @@ public ClientConnectionManager configureConnectionManager(
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(configureScheme());
- ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(schemeRegistry);
+ PoolingClientConnectionManager cm = new PoolingClientConnectionManager(schemeRegistry);
cm.setMaxTotal(maxConnections);
cm.setDefaultMaxPerRoute(maxConnections);
conman = cm;
@@ -338,8 +358,8 @@ public void checkServerTrusted(
params.setParameter(ConnRoutePNames.DEFAULT_PROXY,
new HttpHost(proxy, proxyPort, protocol));
}
- DefaultHttpClient client = new DefaultHttpClient(
- configureConnectionManager(params), params);
+ ClientConnectionManager connectionManager = configureConnectionManager(params);
+ DefaultHttpClient client = new DefaultHttpClient(connectionManager, params);
if (username != null && password != null) {
client.getCredentialsProvider().setCredentials(
new AuthScope(host, port, AuthScope.ANY_REALM),
@@ -348,8 +368,9 @@ public void checkServerTrusted(
new PreemptiveAuthRequestInterceptor(), 0);
}
-
-
+ if (compression) {
+ return new DecompressingHttpClient(client);
+ }
return client;
}
View
@@ -47,7 +47,7 @@
<jackson.version>2.1.0</jackson.version>
<spring.version>3.1.1.RELEASE</spring.version>
<commons.io.version>2.0.1</commons.io.version>
- <httpclient.version>4.1.2</httpclient.version>
+ <httpclient.version>4.2.1</httpclient.version>
<aspectj.version>1.6.9</aspectj.version>
</properties>

0 comments on commit d19933f

Please sign in to comment.