Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: libadblockplus-android/src/org/adblockplus/libadblockplus/android/AndroidWebRequest.java

Issue 29382555: Issue 4977 - Request for compressed response in AndroidWebRequest (Closed)
Left Patch Set: Created March 13, 2017, 6:59 a.m.
Right Patch Set: updated test Created March 28, 2017, 10:02 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « libadblockplus-android/src/org/adblockplus/libadblockplus/android/AdblockEngine.java ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 44
45 public final static String TAG = Utils.getTag(WebRequest.class); 45 public final static String TAG = Utils.getTag(WebRequest.class);
46 46
47 private final HashSet<String> subscriptionURLs = new HashSet<String>(); 47 private final HashSet<String> subscriptionURLs = new HashSet<String>();
48 private final boolean elemhideEnabled; 48 private final boolean elemhideEnabled;
49 private final boolean compressedStream; 49 private final boolean compressedStream;
50 50
51 /** 51 /**
52 * Ctor 52 * Ctor
53 * @param enableElemhide Enable element hiding? 53 * @param enableElemhide Enable element hiding?
54 * Element hiding required significantly more memory 54 * Element hiding requires 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.
55 * but allows to apply element hiding for better ad bloc king 55 * but allows 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.
56 * @param compressedStream Request for gzip compressed stream from the server 56 * @param compressedStream Request for gzip compressed stream from the server
57 */ 57 */
58 public AndroidWebRequest(boolean enableElemhide, boolean compressedStream) 58 public AndroidWebRequest(boolean enableElemhide, boolean compressedStream)
59 { 59 {
60 this.elemhideEnabled = enableElemhide; 60 this.elemhideEnabled = enableElemhide;
61 this.compressedStream = compressedStream; 61 this.compressedStream = compressedStream;
62 } 62 }
63 63
64 public AndroidWebRequest() 64 public AndroidWebRequest()
65 { 65 {
66 this(false, true); 66 this(false, true);
anton 2017/03/13 07:03:34 i believe we should apply gzipping by default.
67 } 67 }
68 68
69 private boolean isListedSubscriptionUrl(final URL url) 69 private boolean isListedSubscriptionUrl(final URL url)
70 { 70 {
71 String toCheck = url.toString(); 71 String toCheck = url.toString();
72 72
73 final int idx = toCheck.indexOf('?'); 73 final int idx = toCheck.indexOf('?');
74 if (idx != -1) 74 if (idx != -1)
75 { 75 {
76 toCheck = toCheck.substring(0, idx); 76 toCheck = toCheck.substring(0, idx);
(...skipping 14 matching lines...) Expand all
91 @Override 91 @Override
92 public ServerResponse httpGET(final String urlStr, final List<HeaderEntry> hea ders) 92 public ServerResponse httpGET(final String urlStr, final List<HeaderEntry> hea ders)
93 { 93 {
94 try 94 try
95 { 95 {
96 final URL url = new URL(urlStr); 96 final URL url = new URL(urlStr);
97 Log.d(TAG, "Downloading from: " + url); 97 Log.d(TAG, "Downloading from: " + url);
98 98
99 final HttpURLConnection connection = (HttpURLConnection) url.openConnectio n(); 99 final HttpURLConnection connection = (HttpURLConnection) url.openConnectio n();
100 connection.setRequestMethod("GET"); 100 connection.setRequestMethod("GET");
101 connection.setRequestProperty("Accept-Encoding", 101 connection.setRequestProperty("Accept-Encoding",
anton 2017/03/13 07:03:34 requesting for gzipping is expected to be done by
102 (compressedStream ? ENCODING_GZIP : ENCODING_IDENTITY)); 102 (compressedStream ? ENCODING_GZIP : ENCODING_IDENTITY));
103 connection.connect(); 103 connection.connect();
104 104
105 final ServerResponse response = new ServerResponse(); 105 final ServerResponse response = new ServerResponse();
106 response.setResponseStatus(connection.getResponseCode()); 106 response.setResponseStatus(connection.getResponseCode());
107 107
108 if (response.getResponseStatus() == 200) 108 if (response.getResponseStatus() == 200)
109 { 109 {
110 final InputStream inputStream = 110 final InputStream inputStream =
111 (compressedStream && ENCODING_GZIP.equals(connection.getContentEncodin g()) 111 (compressedStream && ENCODING_GZIP.equals(connection.getContentEncodin g())
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 Log.d(TAG, "Downloading finished"); 160 Log.d(TAG, "Downloading finished");
161 return response; 161 return response;
162 } 162 }
163 catch (final Throwable t) 163 catch (final Throwable t)
164 { 164 {
165 Log.e(TAG, "WebRequest failed", t); 165 Log.e(TAG, "WebRequest failed", t);
166 throw new AdblockPlusException("WebRequest failed", t); 166 throw new AdblockPlusException("WebRequest failed", t);
167 } 167 }
168 } 168 }
169 } 169 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld