Index: libadblockplus-android/src/org/adblockplus/libadblockplus/android/AndroidWebRequest.java |
diff --git a/libadblockplus-android/src/org/adblockplus/libadblockplus/android/AndroidWebRequest.java b/libadblockplus-android/src/org/adblockplus/libadblockplus/android/AndroidWebRequest.java |
index 848088a909c302cc3780704a707fe1ab35e71298..aa704121a96595b48382fb2e6368c5c258b764f4 100644 |
--- a/libadblockplus-android/src/org/adblockplus/libadblockplus/android/AndroidWebRequest.java |
+++ b/libadblockplus-android/src/org/adblockplus/libadblockplus/android/AndroidWebRequest.java |
@@ -18,6 +18,7 @@ |
package org.adblockplus.libadblockplus.android; |
import java.io.BufferedReader; |
+import java.io.InputStream; |
import java.io.InputStreamReader; |
import java.net.HttpURLConnection; |
import java.net.URL; |
@@ -25,6 +26,7 @@ import java.util.HashSet; |
import java.util.LinkedList; |
import java.util.List; |
import java.util.Map; |
+import java.util.zip.GZIPInputStream; |
import org.adblockplus.libadblockplus.AdblockPlusException; |
import org.adblockplus.libadblockplus.FilterEngine; |
@@ -37,19 +39,31 @@ import android.util.Log; |
public class AndroidWebRequest extends WebRequest |
{ |
+ protected static final String ENCODING_GZIP = "gzip"; |
+ protected static final String ENCODING_IDENTITY = "identity"; |
+ |
public final static String TAG = Utils.getTag(WebRequest.class); |
private final HashSet<String> subscriptionURLs = new HashSet<String>(); |
private final boolean elemhideEnabled; |
- |
- public AndroidWebRequest(boolean enableElemhide) |
+ private final boolean compressedStream; |
+ |
+ /** |
+ * Ctor |
+ * @param enableElemhide Enable element hiding? |
+ * Element hiding required significantly more memory |
diegocarloslima
2017/03/16 19:49:23
I would change here to 'Element hiding requires...
anton
2017/03/17 05:54:44
Acknowledged.
|
+ * but allows to apply element hiding for better ad blocking |
diegocarloslima
2017/03/16 19:49:23
I would shorten here to 'but allows better ad bloc
anton
2017/03/17 05:54:44
Acknowledged.
|
+ * @param compressedStream Request for gzip compressed stream from the server |
+ */ |
+ public AndroidWebRequest(boolean enableElemhide, boolean compressedStream) |
{ |
this.elemhideEnabled = enableElemhide; |
+ this.compressedStream = compressedStream; |
} |
public AndroidWebRequest() |
{ |
- this(false); |
+ this(false, true); |
anton
2017/03/13 07:03:34
i believe we should apply gzipping by default.
|
} |
private boolean isListedSubscriptionUrl(final URL url) |
@@ -84,6 +98,8 @@ public class AndroidWebRequest extends WebRequest |
final HttpURLConnection connection = (HttpURLConnection) url.openConnection(); |
connection.setRequestMethod("GET"); |
+ connection.setRequestProperty("Accept-Encoding", |
anton
2017/03/13 07:03:34
requesting for gzipping is expected to be done by
|
+ (compressedStream ? ENCODING_GZIP : ENCODING_IDENTITY)); |
connection.connect(); |
final ServerResponse response = new ServerResponse(); |
@@ -91,7 +107,11 @@ public class AndroidWebRequest extends WebRequest |
if (response.getResponseStatus() == 200) |
{ |
- final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8")); |
+ final InputStream inputStream = |
+ (compressedStream && ENCODING_GZIP.equals(connection.getContentEncoding()) |
+ ? new GZIPInputStream(connection.getInputStream()) |
+ : connection.getInputStream()); |
+ final BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8")); |
final StringBuilder sb = new StringBuilder(); |
String line; |