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: Created April 11, 2014, 1:31 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 public final static String PROXY_HOST = "proxyHost";
30 public final static String PROXY_PORT = "proxyPort";
31 public final static String AUTH = "auth";
29 32
30 public static final String PROXY_HOST = "proxyHost";
31 public static final String PROXY_PORT = "proxyPort";
32 public static final String AUTH = "auth";
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 this.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);
49
50 try 50 try
51 { 51 {
52 proxyPort = Integer.decode(s).intValue(); 52 this.proxyPort = Integer.decode(s).intValue();
53 } 53 }
54 catch (Exception e) 54 catch (final Exception e)
55 { 55 {
56 } 56 }
57 57
58 auth = props.getProperty(prefix + AUTH); 58 this.auth = props.getProperty(prefix + AUTH);
59 59
60 shouldLogHeaders = (server.props.getProperty(prefix + "proxylog") != null); 60 this.shouldLogHeaders = (server.props.getProperty(prefix + "proxylog") != nu ll);
61 61
62 return true; 62 return true;
63 } 63 }
64 64
65 /** 65 /**
66 * Dump the headers on stderr 66 * Dump the headers on stderr
67 */ 67 */
68 public static String dumpHeaders(int count, Request request, MimeHeaders heade rs, boolean sent) 68 public static String dumpHeaders(final int count, final Request request, final MimeHeaders headers, final boolean sent)
69 { 69 {
70 String prompt; 70 String prompt;
71 StringBuffer sb = new StringBuffer(); 71 final StringBuffer sb = new StringBuffer();
72 String label = " " + count; 72 String label = " " + count;
73 label = label.substring(label.length() - 4); 73 label = label.substring(label.length() - 4);
74 if (sent) 74 if (sent)
75 { 75 {
76 prompt = label + "> "; 76 prompt = label + "> ";
77 sb.append(prompt).append(request.toString()).append("\n"); 77 sb.append(prompt).append(request.toString()).append("\n");
78 } 78 }
79 else 79 else
80 { 80 {
81 prompt = label + "< "; 81 prompt = label + "< ";
82 } 82 }
83 83
84 for (int i = 0; i < headers.size(); i++) 84 for (int i = 0; i < headers.size(); i++)
85 { 85 {
86 sb.append(prompt).append(headers.getKey(i)); 86 sb.append(prompt).append(headers.getKey(i));
87 sb.append(": ").append(headers.get(i)).append("\n"); 87 sb.append(": ").append(headers.get(i)).append("\n");
88 } 88 }
89 return (sb.toString()); 89 return (sb.toString());
90 } 90 }
91 } 91 }
OLDNEW

Powered by Google App Engine
This is Rietveld