diff options
author | Rob Austein <sra@hactrn.net> | 2009-04-28 21:03:38 +0000 |
---|---|---|
committer | Rob Austein <sra@hactrn.net> | 2009-04-28 21:03:38 +0000 |
commit | 08725383287522b6635ba0dc980bdc142f5e0882 (patch) | |
tree | ba2509ca171ac918c10a2581e61d458c43b3c32b /scripts/async-http.py | |
parent | 3e2776e28f26236826b0c78f030ab345aa50d1a0 (diff) |
Checkpoint
svn path=/scripts/async-http.py; revision=2370
Diffstat (limited to 'scripts/async-http.py')
-rw-r--r-- | scripts/async-http.py | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/scripts/async-http.py b/scripts/async-http.py index b757f00b..e9576cff 100644 --- a/scripts/async-http.py +++ b/scripts/async-http.py @@ -23,6 +23,11 @@ PERFORMANCE OF THIS SOFTWARE. # lynx -post_data -mime_header -source http://127.0.0.1:8000/ import sys, os, time, socket, asyncore, asynchat, traceback, urlparse +import rpki.async + +debug = True + +allow_persistence = False class http_message(object): @@ -182,7 +187,7 @@ class http_server(http_stream): print self.msg print msg = http_response(code = 200, reason = "OK", body = self.msg.format(), - Connection = "Keep-Alive" if self.msg.persistent() else "Close", + Connection = "Keep-Alive" if allow_persistence and self.msg.persistent() else "Close", Cache_Control = "no-cache,no-store", Content_Type = "text/plain") @@ -190,17 +195,13 @@ class http_server(http_stream): print msg print self.push(msg.format()) - if self.msg.persistent(): + if allow_persistence and self.msg.persistent(): if debug: print "[Listening for next message]" self.restart() else: if debug: print "[Closing]" self.close_when_done() - def handle_close(self): - if debug: print "[Closing all connections]" - asyncore.close_all() - class http_listener(asyncore.dispatcher): def __init__(self, port): @@ -258,7 +259,7 @@ class http_client(http_stream): self.message_queue.append(msg) def next_msg(self, first): - msg = self.narrator.next_msg(self.hostport, first or self.msg.persistent()) + msg = self.narrator.next_msg(self.hostport, first or (allow_persistence and self.msg.persistent())) if msg is not None: if debug: print "[Got a new message to send from my queue]" self.push(msg.format()) @@ -280,7 +281,9 @@ class http_narrator(object): def query(self, url, body = None): u = urlparse.urlparse(url) assert u.scheme == "http" and u.username is None and u.password is None and u.params == "" and u.query == "" and u.fragment == "" - request = http_request(cmd = "POST", path = u.path, body = body, Content_Type = "text/plain", Connection = "Keep-Alive") + request = http_request(cmd = "POST", path = u.path, body = body, + Content_Type = "text/plain", + Connection = "Keep-Alive" if allow_persistence else "Close") hostport = (u.hostname or "localhost", u.port or 80) if hostport in self.queues: self.queues[hostport].append(request) @@ -302,8 +305,6 @@ class http_narrator(object): else: return None -debug = False - if len(sys.argv) == 1: listener = http_listener(port = 8000) @@ -314,4 +315,4 @@ else: for url in sys.argv[1:]: narrator.query(url = url, body = "Hi, I'm trying to talk to URL %s" % url) -asyncore.loop() +rpki.async.event_loop() |