Commit 5835454d authored by Sam Rushing's avatar Sam Rushing

HTTP_Upgrade: allow a handler to upgrade out of HTTP

parent 78cca542
...@@ -16,7 +16,7 @@ import sys ...@@ -16,7 +16,7 @@ import sys
import time import time
import zlib import zlib
from protocol import latch, http_file, header_set from protocol import latch, http_file, header_set, HTTP_Upgrade
W = sys.stderr.write W = sys.stderr.write
...@@ -70,6 +70,7 @@ class connection: ...@@ -70,6 +70,7 @@ class connection:
self.conn = conn self.conn = conn
self.peer = peer self.peer = peer
self.stream = read_stream.sock_stream (self.conn) self.stream = read_stream.sock_stream (self.conn)
upgrade = False
try: try:
try: try:
for request in request_stream (self, self.stream).gen_requests(): for request in request_stream (self, self.stream).gen_requests():
...@@ -87,6 +88,9 @@ class connection: ...@@ -87,6 +88,9 @@ class connection:
request.wait_until_done() request.wait_until_done()
except (coro.TimeoutError, coro.Interrupted): except (coro.TimeoutError, coro.Interrupted):
raise raise
except HTTP_Upgrade:
upgrade = True
break
except: except:
tb = coro.compact_traceback() tb = coro.compact_traceback()
request.error (500, tb) request.error (500, tb)
...@@ -94,7 +98,8 @@ class connection: ...@@ -94,7 +98,8 @@ class connection:
except (OSError, coro.TimeoutError, coro.ClosedError): except (OSError, coro.TimeoutError, coro.ClosedError):
pass pass
finally: finally:
self.conn.close() if not upgrade:
self.conn.close()
def pick_handler (self, request): def pick_handler (self, request):
for handler in self.server.handlers: for handler in self.server.handlers:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment