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

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

Issue 5697499218051072: Usage of new API, cleanups (reduced) (Closed)
Patch Set: Fixed leftover first-batch review issues. Created April 16, 2014, 5:51 p.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
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.brazil; 18 package org.adblockplus.brazil;
19 19
20 import java.util.Properties; 20 import java.util.Properties;
21 21
22 import sunlabs.brazil.server.Handler; 22 import sunlabs.brazil.server.Handler;
23 import sunlabs.brazil.server.Request; 23 import sunlabs.brazil.server.Request;
24 import sunlabs.brazil.server.Server; 24 import sunlabs.brazil.server.Server;
25 import sunlabs.brazil.util.http.MimeHeaders; 25 import sunlabs.brazil.util.http.MimeHeaders;
26 26
27 public abstract class BaseRequestHandler implements Handler 27 public abstract class BaseRequestHandler implements Handler
28 { 28 {
29
30 public static final String PROXY_HOST = "proxyHost"; 29 public static final String PROXY_HOST = "proxyHost";
31 public static final String PROXY_PORT = "proxyPort"; 30 public static final String PROXY_PORT = "proxyPort";
32 public static final String AUTH = "auth"; 31 public static final String AUTH = "auth";
32
33 protected String proxyHost; 33 protected String proxyHost;
34 protected int proxyPort = 80; 34 protected int proxyPort = 80;
35 protected String auth; 35 protected String auth;
36 protected boolean shouldLogHeaders; 36 protected boolean shouldLogHeaders;
37
38 protected String prefix; 37 protected String prefix;
39 38
40 @Override 39 @Override
41 public boolean init(Server server, String prefix) 40 public boolean init(final Server server, final String prefix)
42 { 41 {
43 this.prefix = prefix; 42 this.prefix = prefix;
44 43
45 Properties props = server.props; 44 final Properties props = server.props;
46 45
47 proxyHost = props.getProperty(prefix + PROXY_HOST); 46 proxyHost = props.getProperty(prefix + PROXY_HOST);
48 47
49 String s = props.getProperty(prefix + PROXY_PORT); 48 final String s = props.getProperty(prefix + PROXY_PORT);
50 try 49 try
51 { 50 {
52 proxyPort = Integer.decode(s).intValue(); 51 proxyPort = Integer.decode(s).intValue();
53 } 52 }
54 catch (Exception e) 53 catch (final Exception e)
55 { 54 {
56 } 55 }
57 56
58 auth = props.getProperty(prefix + AUTH); 57 auth = props.getProperty(prefix + AUTH);
59 58
60 shouldLogHeaders = (server.props.getProperty(prefix + "proxylog") != null); 59 shouldLogHeaders = (server.props.getProperty(prefix + "proxylog") != null);
61 60
62 return true; 61 return true;
63 } 62 }
64 63
65 /** 64 /**
66 * Dump the headers on stderr 65 * Dump the headers on stderr
67 */ 66 */
68 public static String dumpHeaders(int count, Request request, MimeHeaders heade rs, boolean sent) 67 public static String dumpHeaders(final int count, final Request request, final MimeHeaders headers, final boolean sent)
69 { 68 {
70 String prompt; 69 String prompt;
71 StringBuffer sb = new StringBuffer(); 70 final StringBuffer sb = new StringBuffer();
72 String label = " " + count; 71 String label = " " + count;
73 label = label.substring(label.length() - 4); 72 label = label.substring(label.length() - 4);
74 if (sent) 73 if (sent)
75 { 74 {
76 prompt = label + "> "; 75 prompt = label + "> ";
77 sb.append(prompt).append(request.toString()).append("\n"); 76 sb.append(prompt).append(request.toString()).append("\n");
78 } 77 }
79 else 78 else
80 { 79 {
81 prompt = label + "< "; 80 prompt = label + "< ";
82 } 81 }
83 82
84 for (int i = 0; i < headers.size(); i++) 83 for (int i = 0; i < headers.size(); i++)
85 { 84 {
86 sb.append(prompt).append(headers.getKey(i)); 85 sb.append(prompt).append(headers.getKey(i));
87 sb.append(": ").append(headers.get(i)).append("\n"); 86 sb.append(": ").append(headers.get(i)).append("\n");
88 } 87 }
89 return (sb.toString()); 88 return (sb.toString());
90 } 89 }
91 } 90 }
OLDNEW
« no previous file with comments | « src/org/adblockplus/android/updater/UpdaterService.java ('k') | src/org/adblockplus/brazil/RequestHandler.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld