aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libpathod/pathod.py37
-rw-r--r--libpathod/protocols/http.py45
2 files changed, 20 insertions, 62 deletions
diff --git a/libpathod/pathod.py b/libpathod/pathod.py
index 6f25d0c8..63dd1a15 100644
--- a/libpathod/pathod.py
+++ b/libpathod/pathod.py
@@ -122,26 +122,25 @@ class PathodHandler(tcp.BaseHandler):
log: A dictionary, or None
"""
with logger.ctx() as lg:
- if self.use_http2:
+ try:
req = self.protocol.read_request()
- method = req.method
- path = req.path
- headers = odict.ODictCaseless(req.headers)
- httpversion = req.httpversion
- stream_id = req.stream_id
- else:
- req = self.protocol.read_request(lg)
- if 'next_handle' in req:
- return req['next_handle']
- if 'errors' in req:
- return None, req['errors']
- if 'method' not in req or 'path' not in req:
- return None, None
- method = req['method']
- path = req['path']
- headers = req['headers']
- body = req['body']
- httpversion = req['httpversion']
+ except http.HttpError as s:
+ s = str(s)
+ lg(s)
+ return None, dict(type="error", msg=s)
+
+ if isinstance(req, http.EmptyRequest):
+ return None, None
+
+ if isinstance(req, http.ConnectRequest):
+ print([req.host, req.port, req.path])
+ return self.protocol.handle_http_connect([req.host, req.port, req.path], lg)
+
+ method = req.method
+ path = req.path
+ httpversion = req.httpversion
+ headers = odict.ODictCaseless(req.headers)
+ body = req.body
clientcert = None
if self.clientcert:
diff --git a/libpathod/protocols/http.py b/libpathod/protocols/http.py
index d6017882..439e0ba9 100644
--- a/libpathod/protocols/http.py
+++ b/libpathod/protocols/http.py
@@ -68,46 +68,5 @@ class HTTPProtocol:
return None, dict(type="error", msg=s)
return self.pathod_handler.handle_http_request, None
- def read_request(self, lg):
- line = self.wire_protocol.get_request_line()
- if not line:
- # Normal termination
- return dict()
-
- m = utils.MemBool()
- if m(self.wire_protocol.parse_init_connect(line)):
- return dict(next_handle=self.handle_http_connect(m.v, lg))
- elif m(self.wire_protocol.parse_init_proxy(line)):
- method, _, _, _, path, httpversion = m.v
- elif m(self.wire_protocol.parse_init_http(line)):
- method, path, httpversion = m.v
- else:
- s = "Invalid first line: %s" % repr(line)
- lg(s)
- return dict(errors=dict(type="error", msg=s))
-
- headers = self.wire_protocol.read_headers()
- if headers is None:
- s = "Invalid headers"
- lg(s)
- return dict(errors=dict(type="error", msg=s))
-
- try:
- body = self.wire_protocol.read_http_body(
- headers,
- None,
- method,
- None,
- True,
- )
- except http.HttpError as s:
- s = str(s)
- lg(s)
- return dict(errors=dict(type="error", msg=s))
-
- return dict(
- method=method,
- path=path,
- headers=headers,
- body=body,
- httpversion=httpversion)
+ def read_request(self, lg=None):
+ return self.wire_protocol.read_request(allow_empty=True)