OLD | NEW |
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-present eyeo GmbH | 3 * Copyright (C) 2006-present 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 |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 package org.adblockplus.libadblockplus.android; | 18 package org.adblockplus.libadblockplus.android; |
19 | 19 |
20 import java.io.BufferedReader; | 20 import java.io.BufferedReader; |
| 21 import java.io.IOException; |
21 import java.io.InputStream; | 22 import java.io.InputStream; |
22 import java.io.InputStreamReader; | 23 import java.io.InputStreamReader; |
23 import java.net.HttpURLConnection; | 24 import java.net.HttpURLConnection; |
24 import java.net.URL; | 25 import java.net.URL; |
25 import java.util.HashSet; | 26 import java.util.HashSet; |
26 import java.util.LinkedList; | 27 import java.util.LinkedList; |
27 import java.util.List; | 28 import java.util.List; |
28 import java.util.Map; | 29 import java.util.Map; |
29 import java.util.zip.GZIPInputStream; | 30 import java.util.zip.GZIPInputStream; |
30 | 31 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 if (response.getResponseStatus() == 200) | 133 if (response.getResponseStatus() == 200) |
133 { | 134 { |
134 final InputStream inputStream = | 135 final InputStream inputStream = |
135 (compressedStream && ENCODING_GZIP.equals(connection.getContentEncodin
g()) | 136 (compressedStream && ENCODING_GZIP.equals(connection.getContentEncodin
g()) |
136 ? new GZIPInputStream(connection.getInputStream()) | 137 ? new GZIPInputStream(connection.getInputStream()) |
137 : connection.getInputStream()); | 138 : connection.getInputStream()); |
138 final BufferedReader reader = new BufferedReader(new InputStreamReader(i
nputStream, "UTF-8")); | 139 final BufferedReader reader = new BufferedReader(new InputStreamReader(i
nputStream, "UTF-8")); |
139 final StringBuilder sb = new StringBuilder(); | 140 final StringBuilder sb = new StringBuilder(); |
140 | 141 |
141 String line; | 142 String line; |
142 while ((line = reader.readLine()) != null) | 143 try |
143 { | 144 { |
144 // We're only appending non-element-hiding filters here. | 145 while ((line = reader.readLine()) != null) |
145 // | |
146 // See: | |
147 // https://issues.adblockplus.org/ticket/303 | |
148 // | |
149 // Follow-up issue for removing this hack: | |
150 // https://issues.adblockplus.org/ticket/1541 | |
151 // | |
152 if (this.elemhideEnabled || !isListedSubscriptionUrl(url) || line.inde
xOf('#') == -1) | |
153 { | 146 { |
154 sb.append(line); | 147 // We're only appending non-element-hiding filters here. |
155 sb.append('\n'); | 148 // |
| 149 // See: |
| 150 // https://issues.adblockplus.org/ticket/303 |
| 151 // |
| 152 // Follow-up issue for removing this hack: |
| 153 // https://issues.adblockplus.org/ticket/1541 |
| 154 // |
| 155 if (this.elemhideEnabled || !isListedSubscriptionUrl(url) || line.in
dexOf('#') == -1) |
| 156 { |
| 157 sb.append(line); |
| 158 sb.append('\n'); |
| 159 } |
| 160 } |
| 161 } |
| 162 finally |
| 163 { |
| 164 try |
| 165 { |
| 166 reader.close(); |
| 167 } |
| 168 catch (IOException e) |
| 169 { |
| 170 // ignored |
156 } | 171 } |
157 } | 172 } |
158 | 173 |
159 response.setStatus(NsStatus.OK); | 174 response.setStatus(NsStatus.OK); |
160 response.setResponse(sb.toString()); | 175 response.setResponse(sb.toString()); |
161 | 176 |
162 if (connection.getHeaderFields().size() > 0) | 177 if (connection.getHeaderFields().size() > 0) |
163 { | 178 { |
164 List<HeaderEntry> responseHeaders = new LinkedList<HeaderEntry>(); | 179 List<HeaderEntry> responseHeaders = new LinkedList<HeaderEntry>(); |
165 for (Map.Entry<String, List<String>> eachEntry : connection.getHeaderF
ields().entrySet()) | 180 for (Map.Entry<String, List<String>> eachEntry : connection.getHeaderF
ields().entrySet()) |
(...skipping 18 matching lines...) Expand all Loading... |
184 Log.d(TAG, "Downloading finished"); | 199 Log.d(TAG, "Downloading finished"); |
185 return response; | 200 return response; |
186 } | 201 } |
187 catch (final Throwable t) | 202 catch (final Throwable t) |
188 { | 203 { |
189 Log.e(TAG, "WebRequest failed", t); | 204 Log.e(TAG, "WebRequest failed", t); |
190 throw new AdblockPlusException("WebRequest failed", t); | 205 throw new AdblockPlusException("WebRequest failed", t); |
191 } | 206 } |
192 } | 207 } |
193 } | 208 } |
OLD | NEW |