aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2009-05-03 18:19:06 +0000
committerRob Austein <sra@hactrn.net>2009-05-03 18:19:06 +0000
commit8a7bc191437f4f3717051a1465dfa3b668d7e240 (patch)
tree0ebc96d6ce10d144395e78a515bf77e8e63dad83 /scripts
parent05bb55d573e11fabc6a91e94d803282fb4f3e668 (diff)
Checkpoint
svn path=/scripts/async-http.py; revision=2390
Diffstat (limited to 'scripts')
-rw-r--r--scripts/async-http.py30
1 files changed, 24 insertions, 6 deletions
diff --git a/scripts/async-http.py b/scripts/async-http.py
index ae476271..4fd1d5d0 100644
--- a/scripts/async-http.py
+++ b/scripts/async-http.py
@@ -489,14 +489,26 @@ class http_manager(object):
# eg one for callback, one for errback.
-def client(msg, client_key, client_cert, server_ta, url, timeout = 300, callback = None):
+def client(msg, url, timeout = 300, callback = None):
pass
-def server(handlers, port, host =""):
+import signal
+
+def server(handlers, port, host ="", catch_signals = (signal.SIGINT, signal.SIGTERM)):
if not isinstance(handlers, (tuple, list)):
handlers = (("/", handlers),)
- listener = http_listener(port = 8000, handlers = handlers)
- rpki.async.event_loop()
+ try:
+ def raiseExitNow(signum, frame):
+ print "[Signal received, shutting down]"
+ raise asyncore.ExitNow
+ old_signal_handlers = tuple((sig, signal.signal(sig, raiseExitNow)) for sig in catch_signals)
+ listener = http_listener(port = 8000, handlers = handlers)
+ rpki.async.event_loop()
+ except asyncore.ExitNow:
+ pass
+ finally:
+ for sig, handler in old_signal_handlers:
+ signal.signal(sig, handler)
if len(sys.argv) == 1:
@@ -508,9 +520,15 @@ if len(sys.argv) == 1:
Cache_Control = "no-cache,no-store",
Content_Type = "text/plain"))
- server(port = 8000, handlers = handler)
+ def other_handler(query_message, reply_callback):
+ reply_callback(http_response(
+ code = 200,
+ reason = "OK",
+ body = "Ok, you found it.\r\n\r\n" + str(query_message),
+ Cache_Control = "no-cache,no-store",
+ Content_Type = "text/plain"))
- rpki.async.event_loop()
+ server(port = 8000, handlers = (("/wombat", other_handler), ("/", handler)))
else: