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,6 +49,7 @@ class WebRequest(http.Request):
""".replace("\n", "").replace(" ", " ").replace(" ", " ").replace(" ", " ") # Shorten it a bit, bytes wise
def __init__(self, *args, **kwargs):
try:
http.Request.__init__(self, *args, **kwargs)
# Easy factory link
self.factory = self.channel.factory
@ -58,6 +59,8 @@ class WebRequest(http.Request):
self.last_keepalive = time.time()
self.factory.reply_protocols[self.reply_channel] = self
self._got_response_start = False
except Exception:
logger.error(traceback.format_exc())
def process(self):
try:
@ -156,11 +159,11 @@ class WebRequest(http.Request):
self.factory.channel_layer.send("http.request", {
"reply_channel": self.reply_channel,
# 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"),
"path": self.unquote(self.path),
"root_path": self.root_path,
"scheme": "http",
"scheme": "https" if self.isSecure() else "http",
"query_string": self.query_string,
"headers": self.clean_headers,
"body": self.content.read(),