Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add the possibility to handle gzip, deflate content #96

Merged
merged 3 commits into from

2 participants

@pgelinas

This add the possibility for Ektorp to handle gzip, defalte Content-Encoding with the Http queries. Compression isn't a feature that is natively supported by CouchDb, but it is easily achieved by having a reverse proxy do the compression. And since Json is highly compressible, the amount of bandwidth saved is huge.

@helun helun merged commit d19933f into helun:master

1 check passed

Details default The Travis build passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
1  changelog.md
@@ -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
View
31 org.ektorp/src/main/java/org/ektorp/http/StdHttpClient.java
@@ -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
2  pom.xml
@@ -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>
Something went wrong with that request. Please try again.