Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #3 from jgritman/gzip

change gzip and deflate to use httpclient implementations
  • Loading branch information...
commit e27d2733406738bcca653f137e8448ad2619c8d0 2 parents 979d8af + b0a1cb3
@jgritman authored
View
6 pom.xml
@@ -29,7 +29,7 @@
<artifactId>httpclient</artifactId>
<version>4.2.1</version>
</dependency>
- <dependency>
+ <dependency>
<!-- Only needed for JSON parsing -->
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
@@ -49,7 +49,7 @@
<artifactId>xom</artifactId>
</exclusion>
</exclusions>
- </dependency>
+ </dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy</artifactId>
@@ -196,7 +196,7 @@
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemProperties>
- <property>
+ <property>
<name>xml.catalog.verbosity</name>
<value>9</value>
</property>
View
38 src/main/java/groovyx/net/http/DeflateEncoding.java
@@ -23,12 +23,8 @@
import static groovyx.net.http.ContentEncoding.Type.DEFLATE;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.zip.InflaterInputStream;
-
import org.apache.http.HttpEntity;
-import org.apache.http.entity.HttpEntityWrapper;
+import org.apache.http.client.entity.DeflateDecompressingEntity;
/**
* Content encoding used to handle Deflate responses.
@@ -51,37 +47,7 @@ public String getContentEncoding() {
*/
@Override
public HttpEntity wrapResponseEntity( HttpEntity raw ) {
- return new InflaterEntity( raw );
- }
-
- /**
- * Entity used to interpret a Deflate-encoded response
- * @author <a href='mailto:tomstrummer+httpbuilder@gmail.com'>Tom Nichols</a>
- */
- public static class InflaterEntity extends HttpEntityWrapper {
-
- public InflaterEntity(final HttpEntity entity) {
- super(entity);
- }
-
- /**
- * returns a {@link InflaterInputStream} which wraps the original entity's
- * content stream
- * @see HttpEntity#getContent()
- */
- @Override
- public InputStream getContent() throws IOException, IllegalStateException {
- return new InflaterInputStream( wrappedEntity.getContent() );
- }
-
- /**
- * @return -1
- */
- @Override
- public long getContentLength() {
- // length of ungzipped content is not known
- return -1;
- }
+ return new DeflateDecompressingEntity( raw );
}
}
View
37 src/main/java/groovyx/net/http/GZIPEncoding.java
@@ -23,12 +23,8 @@
import static groovyx.net.http.ContentEncoding.Type.GZIP;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.zip.GZIPInputStream;
-
import org.apache.http.HttpEntity;
-import org.apache.http.entity.HttpEntityWrapper;
+import org.apache.http.client.entity.GzipDecompressingEntity;
/**
* Content encoding used to handle GZIP responses.
@@ -50,36 +46,7 @@ public String getContentEncoding() {
*/
@Override
public HttpEntity wrapResponseEntity( HttpEntity raw ) {
- return new GZIPDecompressingEntity( raw );
+ return new GzipDecompressingEntity( raw );
}
- /**
- * Entity used to interpret a GZIP-encoded response
- * @author <a href='mailto:tomstrummer+httpbuilder@gmail.com'>Tom Nichols</a>
- */
- protected static class GZIPDecompressingEntity extends HttpEntityWrapper {
-
- public GZIPDecompressingEntity(final HttpEntity entity) {
- super(entity);
- }
-
- /**
- * returns a {@link GZIPInputStream} which wraps the original entity's
- * content stream
- * @see HttpEntity#getContent()
- */
- @Override
- public InputStream getContent() throws IOException, IllegalStateException {
- return new GZIPInputStream( wrappedEntity.getContent() );
- }
-
- /**
- * @return -1
- */
- @Override
- public long getContentLength() {
- // length of un-gzipped content is not known
- return -1;
- }
- }
}
View
2  src/test/groovy/groovyx/net/http/HTTPBuilderTest.groovy
@@ -289,7 +289,7 @@ class HTTPBuilderTest {
//UA header required to get Google to GZIP response:
headers.'User-Agent' = "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.0.4) Gecko/2008111319 Ubuntu/8.10 (intrepid) Firefox/3.0.4"
response.success = { resp, json ->
- assert resp.entity.contentEncoding.value == 'gzip'
+ assert resp.headers['Content-Encoding'].value == "gzip"
assert json.size() == 3
//println json.responseData
println "Query response: "
View
4 src/test/groovy/groovyx/net/http/thirdparty/GAETest.groovy
@@ -305,7 +305,7 @@ class GAETest {
//UA header required to get Google to GZIP response:
headers.'User-Agent' = "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.0.4) Gecko/2008111319 Ubuntu/8.10 (intrepid) Firefox/3.0.4"
response.success = { resp, json ->
- assert resp.entity.contentEncoding.value == 'gzip'
+ assert resp.headers['Content-Encoding'].value == "gzip"
assert json.size() == 3
//println json.responseData
println "Query response: "
@@ -358,4 +358,4 @@ class GAETest {
}
}
}
-}
+}

0 comments on commit e27d273

Please sign in to comment.
Something went wrong with that request. Please try again.