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

Side by Side Diff: src/org/adblockplus/brazil/RequestHandler.java

Issue 4705284891082752: Proxy configurators (Closed)
Patch Set: Last batch of review issues Created Aug. 24, 2014, 11:52 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
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 11 matching lines...) Expand all
22 import java.io.FilterOutputStream; 22 import java.io.FilterOutputStream;
23 import java.io.IOException; 23 import java.io.IOException;
24 import java.io.InterruptedIOException; 24 import java.io.InterruptedIOException;
25 import java.io.OutputStream; 25 import java.io.OutputStream;
26 import java.net.ConnectException; 26 import java.net.ConnectException;
27 import java.net.MalformedURLException; 27 import java.net.MalformedURLException;
28 import java.net.URL; 28 import java.net.URL;
29 import java.net.UnknownHostException; 29 import java.net.UnknownHostException;
30 import java.nio.charset.Charset; 30 import java.nio.charset.Charset;
31 import java.util.List; 31 import java.util.List;
32 import java.util.concurrent.atomic.AtomicLong;
32 import java.util.regex.Matcher; 33 import java.util.regex.Matcher;
33 import java.util.regex.Pattern; 34 import java.util.regex.Pattern;
34 import java.util.zip.GZIPInputStream; 35 import java.util.zip.GZIPInputStream;
35 import java.util.zip.InflaterInputStream; 36 import java.util.zip.InflaterInputStream;
36 37
37 import org.adblockplus.ChunkedOutputStream; 38 import org.adblockplus.ChunkedOutputStream;
38 import org.adblockplus.android.AdblockPlus; 39 import org.adblockplus.android.AdblockPlus;
39 import org.apache.commons.lang.StringUtils; 40 import org.apache.commons.lang.StringUtils;
40 import org.literateprograms.BoyerMoore; 41 import org.literateprograms.BoyerMoore;
41 42
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 * See the description under {@link sunlabs.brazil.server.Handler#respond 80 * See the description under {@link sunlabs.brazil.server.Handler#respond
80 * respond} for a more detailed explanation. 81 * respond} for a more detailed explanation.
81 */ 82 */
82 83
83 public class RequestHandler extends BaseRequestHandler 84 public class RequestHandler extends BaseRequestHandler
84 { 85 {
85 private AdblockPlus application; 86 private AdblockPlus application;
86 private String via; 87 private String via;
87 private static final Pattern RE_HTTP = Pattern.compile("^https?:"); 88 private static final Pattern RE_HTTP = Pattern.compile("^https?:");
88 89
90 private static final AtomicLong BLOCKED_REQUESTS = new AtomicLong();
91 private static final AtomicLong UNBLOCKED_REQUESTS = new AtomicLong();
92
93 public static long getBlockedRequestCount()
94 {
95 return BLOCKED_REQUESTS.get();
96 }
97
98 public static long getUnblockedRequestCount()
99 {
100 return UNBLOCKED_REQUESTS.get();
101 }
102
89 @Override 103 @Override
90 public boolean init(final Server server, final String prefix) 104 public boolean init(final Server server, final String prefix)
91 { 105 {
92 super.init(server, prefix); 106 super.init(server, prefix);
93 107
94 application = AdblockPlus.getApplication(); 108 application = AdblockPlus.getApplication();
95 via = " " + server.hostName + ":" + server.listen.getLocalPort() + " (" + se rver.name + ")"; 109 via = " " + server.hostName + ":" + server.listen.getLocalPort() + " (" + se rver.name + ")";
96 110
97 return true; 111 return true;
98 } 112 }
(...skipping 10 matching lines...) Expand all
109 catch (final Exception e) 123 catch (final Exception e)
110 { 124 {
111 Log.e(prefix, "Filter error", e); 125 Log.e(prefix, "Filter error", e);
112 } 126 }
113 127
114 request.log(Server.LOG_LOG, prefix, block + ": " + request.url); 128 request.log(Server.LOG_LOG, prefix, block + ": " + request.url);
115 129
116 int count = request.server.requestCount; 130 int count = request.server.requestCount;
117 if (shouldLogHeaders) 131 if (shouldLogHeaders)
118 { 132 {
133 // FIXME Don't log to "err"
119 System.err.println(dumpHeaders(count, request, request.headers, true)); 134 System.err.println(dumpHeaders(count, request, request.headers, true));
120 } 135 }
121 136
122 if (block) 137 if (block)
123 { 138 {
124 request.sendHeaders(204, null, 0); 139 request.sendHeaders(204, null, 0);
140 BLOCKED_REQUESTS.incrementAndGet();
125 return true; 141 return true;
126 } 142 }
127 143
144 UNBLOCKED_REQUESTS.incrementAndGet();
145
128 // Do not further process non-http requests 146 // Do not further process non-http requests
129 if (!RE_HTTP.matcher(request.url).find()) 147 if (!RE_HTTP.matcher(request.url).find())
130 { 148 {
131 return false; 149 return false;
132 } 150 }
133 151
134 String url = request.url; 152 String url = request.url;
135 153
136 if ((request.query != null) && (request.query.length() > 0)) 154 if ((request.query != null) && (request.query.length() > 0))
137 { 155 {
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 request.sendError(500, msg); 402 request.sendError(500, msg);
385 Log.e(prefix, msg, e); 403 Log.e(prefix, msg, e);
386 } 404 }
387 finally 405 finally
388 { 406 {
389 target.close(); 407 target.close();
390 } 408 }
391 return true; 409 return true;
392 } 410 }
393 } 411 }
OLDNEW

Powered by Google App Engine
This is Rietveld