Skip to content

Commit

Permalink
Merge pull request #175 from bogas04/deflateSupport
Browse files Browse the repository at this point in the history
add deflate encoded response support. closes #173
  • Loading branch information
hrj committed Oct 3, 2015
2 parents 6cf4508 + efe17ab commit a3d5dba
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
23 changes: 19 additions & 4 deletions src/Common/org/lobobrowser/util/io/IORoutines.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.util.Collection;
import java.util.stream.Collectors;
import java.util.zip.GZIPInputStream;
import java.util.zip.InflaterInputStream;

/**
* @author J. H. S.
Expand Down Expand Up @@ -197,18 +198,32 @@ public static java.util.List<String> loadStrings(final File file) throws IOExcep

public static InputStream getDecodedStream(final URLConnection connection) throws IOException {
final InputStream cis = connection.getInputStream();
final InputStream is = "gzip".equals(connection.getContentEncoding()) ? new GZIPInputStream(cis) : cis;
final InputStream is;
if ("gzip".equals(connection.getContentEncoding())) {
is = new GZIPInputStream(cis);
} else if ("deflate".equals(connection.getContentEncoding())) {
is = new InflaterInputStream(cis);
} else {
is = cis;
}
return is;
}

public static InputStream getDecodedErrorStream(final HttpURLConnection connection) throws IOException {
final InputStream cis = connection.getErrorStream();
final InputStream is;
if (cis != null) {
final InputStream is = "gzip".equals(connection.getContentEncoding()) ? new GZIPInputStream(cis) : cis;
return is;
if ("gzip".equals(connection.getContentEncoding())) {
is = new GZIPInputStream(cis);
} else if ("deflate".equals(connection.getContentEncoding())) {
is = new InflaterInputStream(cis);
} else {
is = cis;
}
} else {
return null;
is = null;
}
return is;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ private static void addRequestProperties(final URLConnection connection, final C
final URL lastRequestURL, final RequestHandler rhandler) throws ProtocolException {
final UserAgent userAgent = request.getUserAgent();
connection.addRequestProperty("User-Agent", userAgent.toString());
connection.addRequestProperty("Accept-Encoding", "gzip");
connection.addRequestProperty("Accept-Encoding", "gzip, deflate");

// TODO: Harshad: Commenting out X-Java-Version. Check if required.
// connection.addRequestProperty("X-Java-Version", userAgent.getJavaVersion());
Expand Down

0 comments on commit a3d5dba

Please sign in to comment.