aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2007-08-09 03:46:14 +0000
committerRob Austein <sra@hactrn.net>2007-08-09 03:46:14 +0000
commit0838db9c7b7a720a838aa8eb9a87ad14f5a4a30a (patch)
treee842b62f104143422a3714e07b43b17c8234663c /scripts
parentdc6a8bf731bb4aae8c71f8540c581c83838bc109 (diff)
Cleanup
svn path=/scripts/http-server.py; revision=849
Diffstat (limited to 'scripts')
-rw-r--r--scripts/http-server.py6
-rw-r--r--scripts/rpki/https.py19
2 files changed, 17 insertions, 8 deletions
diff --git a/scripts/http-server.py b/scripts/http-server.py
index e5e63dc6..9ceaf78f 100644
--- a/scripts/http-server.py
+++ b/scripts/http-server.py
@@ -4,7 +4,7 @@ import rpki.https, tlslite.api
certInfo = rpki.https.CertInfo("Carol")
-def handler(self, query):
- return 200, "I got:\n" + query
+def handler(query, path):
+ return 200, "Path: %s\nQuery: %s" % (path, query)
-rpki.https.server(certInfo=certInfo, handler=handler)
+rpki.https.server(certInfo=certInfo, handlers={"/" : handler})
diff --git a/scripts/rpki/https.py b/scripts/rpki/https.py
index 078dce56..1eb6412c 100644
--- a/scripts/rpki/https.py
+++ b/scripts/rpki/https.py
@@ -43,12 +43,21 @@ def client(msg, certInfo, host="localhost", port=4433, url="/"):
class requestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
- rpki_handler = None # Subclass must bind
+ rpki_handlers = None # Subclass must bind
def do_POST(self):
assert self.headers["Content-Type"] == rpki_content_type
- self.query_string = self.rfile.read(int(self.headers["Content-Length"]))
- rcode, rtext = self.rpki_handler(self.query_string)
+ query_string = self.rfile.read(int(self.headers["Content-Length"]))
+ rcode = None
+ try:
+ handler = self.rpki_handlers[self.path]
+ except KeyError:
+ rcode, rtext = 404, ""
+ if rcode is None:
+ try:
+ rcode, rtext = handler(query=query_string, path=self.path)
+ except:
+ rcode, rtext = 500, ""
self.send_response(rcode)
self.send_header("Content-Type", rpki_content_type)
self.end_headers()
@@ -74,13 +83,13 @@ class httpServer(tlslite.api.TLSSocketServerMixIn, BaseHTTPServer.HTTPServer):
print "TLS handshake failure:", str(error)
return False
-def server(handler, certInfo, port=4433, host=""):
+def server(handlers, certInfo, port=4433, host=""):
# BaseHTTPServer.HTTPServer takes a class, not an instance, so
# binding our handler requires creating a new subclass. Weird.
class boundRequestHandler(requestHandler):
- rpki_handler = handler
+ rpki_handlers = handlers
httpd = httpServer((host, port), boundRequestHandler)
httpd.rpki_privateKey = certInfo.privateKey