| LEFT | RIGHT |
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2014 Eyeo GmbH | 3 * Copyright (C) 2006-2014 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 30 matching lines...) Expand all Loading... |
| 41 | 41 |
| 42 import sunlabs.brazil.server.Request; | 42 import sunlabs.brazil.server.Request; |
| 43 import sunlabs.brazil.server.Server; | 43 import sunlabs.brazil.server.Server; |
| 44 import sunlabs.brazil.util.MatchString; | 44 import sunlabs.brazil.util.MatchString; |
| 45 import sunlabs.brazil.util.http.HttpInputStream; | 45 import sunlabs.brazil.util.http.HttpInputStream; |
| 46 import sunlabs.brazil.util.http.HttpRequest; | 46 import sunlabs.brazil.util.http.HttpRequest; |
| 47 import android.util.Log; | 47 import android.util.Log; |
| 48 | 48 |
| 49 /** | 49 /** |
| 50 * The <code>RequestHandler</code> implements a proxy service optionally | 50 * The <code>RequestHandler</code> implements a proxy service optionally |
| 51 * modifying output. The | 51 * modifying output. |
| 52 * following configuration parameters are used to initialize this | 52 * The following configuration parameters are used to initialize this |
| 53 * <code>Handler</code>: | 53 * <code>Handler</code>: |
| 54 * <dl class=props> | 54 * <dl class=props> |
| 55 * | 55 * |
| 56 * <dt>prefix, suffix, glob, match | 56 * <dt>prefix, suffix, glob, match |
| 57 * <dd>Specify the URL that triggers this handler. (See {@link MatchString}). | 57 * <dd>Specify the URL that triggers this handler. (See {@link MatchString}). |
| 58 * <dt>auth | 58 * <dt>auth |
| 59 * <dd>The value of the proxy-authenticate header (if any) sent to the upstream | 59 * <dd>The value of the proxy-authenticate header (if any) sent to the upstream |
| 60 * proxy | 60 * proxy |
| 61 * <dt>proxyHost | 61 * <dt>proxyHost |
| 62 * <dd>If specified, the name of the upstream proxy | 62 * <dd>If specified, the name of the upstream proxy |
| (...skipping 12 matching lines...) Expand all Loading... |
| 75 * handler=adblock | 75 * handler=adblock |
| 76 * adblock.class=org.adblockplus.brazil.RequestHandler | 76 * adblock.class=org.adblockplus.brazil.RequestHandler |
| 77 * </pre> | 77 * </pre> |
| 78 * | 78 * |
| 79 * See the description under {@link sunlabs.brazil.server.Handler#respond | 79 * See the description under {@link sunlabs.brazil.server.Handler#respond |
| 80 * respond} for a more detailed explanation. | 80 * respond} for a more detailed explanation. |
| 81 */ | 81 */ |
| 82 | 82 |
| 83 public class RequestHandler extends BaseRequestHandler | 83 public class RequestHandler extends BaseRequestHandler |
| 84 { | 84 { |
| 85 private static final Pattern RE_HTTP = Pattern.compile("^https?:"); | |
| 86 | |
| 87 private AdblockPlus application; | 85 private AdblockPlus application; |
| 88 private String via; | 86 private String via; |
| 87 private static final Pattern RE_HTTP = Pattern.compile("^https?:"); |
| 89 | 88 |
| 90 @Override | 89 @Override |
| 91 public boolean init(final Server server, final String prefix) | 90 public boolean init(final Server server, final String prefix) |
| 92 { | 91 { |
| 93 super.init(server, prefix); | 92 super.init(server, prefix); |
| 94 | 93 |
| 95 application = AdblockPlus.getApplication(); | 94 application = AdblockPlus.getApplication(); |
| 96 via = " " + server.hostName + ":" + server.listen.getLocalPort() + " (" + se
rver.name + ")"; | 95 via = " " + server.hostName + ":" + server.listen.getLocalPort() + " (" + se
rver.name + ")"; |
| 97 | 96 |
| 98 return true; | 97 return true; |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 } | 337 } |
| 339 catch (final IOException e) | 338 catch (final IOException e) |
| 340 { | 339 { |
| 341 break; | 340 break; |
| 342 } | 341 } |
| 343 } | 342 } |
| 344 // The correct way would be to close ChunkedOutputStream | 343 // The correct way would be to close ChunkedOutputStream |
| 345 // but we can not do it because underlying output stream is | 344 // but we can not do it because underlying output stream is |
| 346 // used later in caller code. So we use this ugly hack: | 345 // used later in caller code. So we use this ugly hack: |
| 347 if (out instanceof ChunkedOutputStream) | 346 if (out instanceof ChunkedOutputStream) |
| 348 { | |
| 349 ((ChunkedOutputStream) out).writeFinalChunk(); | 347 ((ChunkedOutputStream) out).writeFinalChunk(); |
| 350 } | |
| 351 } | 348 } |
| 352 } | 349 } |
| 353 catch (final InterruptedIOException e) | 350 catch (final InterruptedIOException e) |
| 354 { | 351 { |
| 355 /* | 352 /* |
| 356 * Read timeout while reading from the remote side. We use a | 353 * Read timeout while reading from the remote side. We use a |
| 357 * read timeout in case the target never responds. | 354 * read timeout in case the target never responds. |
| 358 */ | 355 */ |
| 359 request.sendError(408, "Timeout / No response"); | 356 request.sendError(408, "Timeout / No response"); |
| 360 } | 357 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 387 request.sendError(500, msg); | 384 request.sendError(500, msg); |
| 388 Log.e(prefix, msg, e); | 385 Log.e(prefix, msg, e); |
| 389 } | 386 } |
| 390 finally | 387 finally |
| 391 { | 388 { |
| 392 target.close(); | 389 target.close(); |
| 393 } | 390 } |
| 394 return true; | 391 return true; |
| 395 } | 392 } |
| 396 } | 393 } |
| LEFT | RIGHT |