60 |
public HTTPProxy(IndexedPool pool, int port) throws IOException { |
public HTTPProxy(IndexedPool pool, int port) throws IOException { |
61 |
this.pool = pool; |
this.pool = pool; |
62 |
this.port = port; |
this.port = port; |
63 |
|
System.out.println("BAR"); |
64 |
this.addr = InetAddress.getLocalHost().getHostName(); |
this.addr = InetAddress.getLocalHost().getHostName(); |
65 |
|
System.out.println("BAR"); |
66 |
this.ROOTURL = "http://"+addr+":"+port+"/"; |
this.ROOTURL = "http://"+addr+":"+port+"/"; |
67 |
this.REWRITE = "rewrite"; |
this.REWRITE = "rewrite"; |
68 |
this.BACKLINKS = "backlinks"; |
this.BACKLINKS = "backlinks"; |
69 |
this.URNPAC = "urn-proxy.pac"; |
this.URNPAC = "urn-proxy.pac"; |
70 |
|
System.out.println("BAR"); |
71 |
|
|
72 |
this.server = new HTTPServer(new Factory(), port); |
this.server = new HTTPServer(new Factory(), port); |
73 |
|
System.out.println("BAR"); |
74 |
} |
} |
75 |
|
|
76 |
/** Construct a gateway that allows PUT to pointer URNs. |
/** Construct a gateway that allows PUT to pointer URNs. |
521 |
if(!acceptPut) |
if(!acceptPut) |
522 |
return doUnknown(req, resf); |
return doUnknown(req, resf); |
523 |
|
|
524 |
if(!uri.equals("/new-pointer")) |
if(!uri.equals("/new-pointer") && |
525 |
|
!uri.equals("/new-pointer-plain")) |
526 |
return resf.makeError(404, "Not found"); |
return resf.makeError(404, "Not found"); |
527 |
|
|
528 |
String formdata = |
String formdata = |
559 |
} |
} |
560 |
|
|
561 |
HTTPResponse resp = resf.makeResponse(203, "Created"); |
HTTPResponse resp = resf.makeResponse(203, "Created"); |
|
resp.setField("Content-Type", "text/html"); |
|
562 |
resp.setField("Location", target.getURI()); |
resp.setField("Location", target.getURI()); |
563 |
Writer w = new OutputStreamWriter(resp.getOutputStream(), |
|
564 |
"US-ASCII"); |
if(uri.equals("/new-pointer-plain")) { |
565 |
w.write("<html><head><title>Created</title></head><body>"); |
resp.setField("Content-Type", "text/plain"); |
566 |
w.write("New pointer created at: \n"); |
Writer w = new OutputStreamWriter(resp.getOutputStream(), |
567 |
w.write("<a href=\""+id.getURI()+"\">"+id.getURI()+"</a>\n"); |
"US-ASCII"); |
568 |
w.write("<p><a href=\"/\">Back to the home page.</a>\n"); |
w.write(id.getURI()); |
569 |
w.write("</body></html>"); |
w.close(); |
570 |
w.close(); |
} else { |
571 |
|
resp.setField("Content-Type", "text/html"); |
572 |
|
Writer w = new OutputStreamWriter(resp.getOutputStream(), |
573 |
|
"US-ASCII"); |
574 |
|
w.write("<html><head><title>Created</title></head><body>"); |
575 |
|
w.write("New pointer created at: \n"); |
576 |
|
w.write("<a href=\""+id.getURI()+"\">"+id.getURI()+"</a>\n"); |
577 |
|
w.write("<p><a href=\"/\">Back to the home page.</a>\n"); |
578 |
|
w.write("</body></html>"); |
579 |
|
w.close(); |
580 |
|
} |
581 |
|
|
582 |
if(dbg) p("Return response"); |
if(dbg) p("Return response"); |
583 |
return resp; |
return resp; |
669 |
if(args.length == 1) |
if(args.length == 1) |
670 |
new HTTPProxy(pool, 5555).run(); |
new HTTPProxy(pool, 5555).run(); |
671 |
else { |
else { |
672 |
|
System.out.println("FOO"); |
673 |
KeyPair keys = SetPointer.readKeyPair(new File(args[1])); |
KeyPair keys = SetPointer.readKeyPair(new File(args[1])); |
674 |
|
System.out.println("FOO"); |
675 |
new HTTPProxy(pool, 5555, keys).run(); |
new HTTPProxy(pool, 5555, keys).run(); |
676 |
} |
} |
677 |
} |
} |