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-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2015 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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 via = " " + server.hostName + ":" + server.listen.getLocalPort() + " (" + se
rver.name + ")"; | 109 via = " " + server.hostName + ":" + server.listen.getLocalPort() + " (" + se
rver.name + ")"; |
110 | 110 |
111 return true; | 111 return true; |
112 } | 112 } |
113 | 113 |
114 @Override | 114 @Override |
115 public boolean respond(final Request request) throws IOException | 115 public boolean respond(final Request request) throws IOException |
116 { | 116 { |
117 boolean block = false; | 117 boolean block = false; |
118 | 118 |
| 119 final String referer = request.getRequestHeader("referer"); |
119 try | 120 try |
120 { | 121 { |
121 block = application.matches(request.url, request.query, request.getRequest
Header("referer"), request.getRequestHeader("accept")); | 122 block = application.matches(request.url, request.query, referer, request.g
etRequestHeader("accept")); |
122 } | 123 } |
123 catch (final Exception e) | 124 catch (final Exception e) |
124 { | 125 { |
125 Log.e(prefix, "Filter error", e); | 126 Log.e(prefix, "Filter error", e); |
126 } | 127 } |
127 | 128 |
128 request.log(Server.LOG_LOG, prefix, block + ": " + request.url); | 129 request.log(Server.LOG_LOG, prefix, block + ": " + request.url); |
129 | 130 |
130 int count = request.server.requestCount; | 131 int count = request.server.requestCount; |
131 if (shouldLogHeaders) | 132 if (shouldLogHeaders) |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 | 224 |
224 try | 225 try |
225 { | 226 { |
226 reqHost = (new URL(request.url)).getHost(); | 227 reqHost = (new URL(request.url)).getHost(); |
227 } | 228 } |
228 catch (final MalformedURLException e) | 229 catch (final MalformedURLException e) |
229 { | 230 { |
230 // We are transparent, it's not our deal if it's malformed. | 231 // We are transparent, it's not our deal if it's malformed. |
231 } | 232 } |
232 | 233 |
233 selectors = application.getSelectorsForDomain(reqHost); | 234 selectors = application.getSelectorsForDomain(reqHost, referer); |
234 } | 235 } |
235 // If no filters are applicable just pass through the response | 236 // If no filters are applicable just pass through the response |
236 if (selectors == null || target.getResponseCode() != 200) | 237 if (selectors == null || target.getResponseCode() != 200) |
237 { | 238 { |
238 final int contentLength = target.getContentLength(); | 239 final int contentLength = target.getContentLength(); |
239 if (contentLength == 0) | 240 if (contentLength == 0) |
240 { | 241 { |
241 // we do not use request.sendResponse to avoid arbitrary | 242 // we do not use request.sendResponse to avoid arbitrary |
242 // 200 -> 204 response code conversion | 243 // 200 -> 204 response code conversion |
243 request.sendHeaders(-1, null, -1); | 244 request.sendHeaders(-1, null, -1); |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 request.sendError(500, msg); | 403 request.sendError(500, msg); |
403 Log.e(prefix, msg, e); | 404 Log.e(prefix, msg, e); |
404 } | 405 } |
405 finally | 406 finally |
406 { | 407 { |
407 target.close(); | 408 target.close(); |
408 } | 409 } |
409 return true; | 410 return true; |
410 } | 411 } |
411 } | 412 } |
OLD | NEW |