File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed
Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change 33import java .util .*;
44
55public class ProxyCache {
6+ private static boolean secure = false ;
7+ public static boolean expires = false ;
8+
69 /** Port for the proxy */
710 private static int port ;
811 /** Socket for client connections */
@@ -81,7 +84,7 @@ public static void handle(Socket client) {
8184
8285 // http://stackoverflow.com/questions/16358589/implementing-a-simple-https-proxy-application-with-java
8386 // http://stackoverflow.com/questions/18273703/tunneling-two-socket-client-in-java#18274109
84- else if (request .method .equals ("CONNECT" )) {
87+ else if (secure && request .method .equals ("CONNECT" )) {
8588 System .out .println ("CONNECT found! Tunnelling HTTPS connection." );
8689 InputStream fromClient ;
8790 OutputStream toServer ;
@@ -155,6 +158,20 @@ else if (request.method.equals("CONNECT")) {
155158
156159 /** Read command line arguments and start proxy */
157160 public static void main (String args []) {
161+ for (String argument : args ) { // http://java.about.com/od/javasyntax/a/Using-Command-Line-Arguments.htm
162+ if (argument .equals ("-s" ) || argument .equals ("--secure" )) {
163+ // proxy secure HTTPS/TLS connections (experimental as it can course 100% CPU usage)
164+ secure = true ;
165+ System .out .print ("Proxy HTTPS/TLS connections. (experimental as it can course 100% CPU usage)\n " );
166+
167+ }
168+ if (argument .equals ("-e" ) || argument .equals ("--expires" )) {
169+ // when validating the cache also check the expires header, this can reduce the number of requests out to the web.
170+ expires = true ;
171+ System .out .print ("Check expires headers when checking the freshniss of an object in the cache.\n " );
172+ }
173+ }
174+
158175 int myPort = 0 ;
159176
160177 try {
Original file line number Diff line number Diff line change @@ -69,7 +69,7 @@ public HttpResponse get(String key) {
6969 * @return isValid? as in is the item in the cache fresh?
7070 */
7171 public boolean isValid (String requestURL , HttpResponse response ) {
72- if (!response .isExpired ()) { // TODO: add command line flag
72+ if (ProxyCache . expires && !response .isExpired ()) { // TODO: add command line flag
7373 System .out .println ("SCACHE: response has not expired" );
7474 return true ;
7575 }
You can’t perform that action at this time.
0 commit comments