Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added option to activate gzip/deflate compression for request with Co…

…uchDB.
  • Loading branch information...
commit 137e3f1826342ddfb0bca92a7864ffd7cbf20b20 1 parent d93d551
@pgelinas pgelinas authored
View
29 org.ektorp/src/main/java/org/ektorp/http/StdHttpClient.java
@@ -29,6 +29,8 @@
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.ContentEncodingHttpClient;
+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;
@@ -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.
@@ -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>
Please sign in to comment.
Something went wrong with that request. Please try again.