Try to handle HTTP version and SSL correctly (plus better errors)

This commit is contained in:
Andrew Godwin 2017-03-28 11:23:51 -07:00
parent 3937489c4a
commit 4a764f7966

View File

@ -49,15 +49,18 @@ class WebRequest(http.Request):
""".replace("\n", "").replace(" ", " ").replace(" ", " ").replace(" ", " ") # Shorten it a bit, bytes wise """.replace("\n", "").replace(" ", " ").replace(" ", " ").replace(" ", " ") # Shorten it a bit, bytes wise
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
http.Request.__init__(self, *args, **kwargs) try:
# Easy factory link http.Request.__init__(self, *args, **kwargs)
self.factory = self.channel.factory # Easy factory link
# Make a name for our reply channel self.factory = self.channel.factory
self.reply_channel = self.factory.make_send_channel() # Make a name for our reply channel
# Tell factory we're that channel's client self.reply_channel = self.factory.make_send_channel()
self.last_keepalive = time.time() # Tell factory we're that channel's client
self.factory.reply_protocols[self.reply_channel] = self self.last_keepalive = time.time()
self._got_response_start = False self.factory.reply_protocols[self.reply_channel] = self
self._got_response_start = False
except Exception:
logger.error(traceback.format_exc())
def process(self): def process(self):
try: try:
@ -156,11 +159,11 @@ class WebRequest(http.Request):
self.factory.channel_layer.send("http.request", { self.factory.channel_layer.send("http.request", {
"reply_channel": self.reply_channel, "reply_channel": self.reply_channel,
# TODO: Correctly say if it's 1.1 or 1.0 # TODO: Correctly say if it's 1.1 or 1.0
"http_version": "1.1", "http_version": self.clientproto.split("/")[-1],
"method": self.method.decode("ascii"), "method": self.method.decode("ascii"),
"path": self.unquote(self.path), "path": self.unquote(self.path),
"root_path": self.root_path, "root_path": self.root_path,
"scheme": "http", "scheme": "https" if self.isSecure() else "http",
"query_string": self.query_string, "query_string": self.query_string,
"headers": self.clean_headers, "headers": self.clean_headers,
"body": self.content.read(), "body": self.content.read(),