diff options
author | Thomas Kriechbaumer <thomas@kriechbaumer.name> | 2015-07-19 20:10:07 +0200 |
---|---|---|
committer | Thomas Kriechbaumer <thomas@kriechbaumer.name> | 2015-07-22 15:30:34 +0200 |
commit | 1a9c1a8c2d6ccedd2248a676a6b3235c8cf86147 (patch) | |
tree | bbdfc615cf28cd415085197cb0f4764139c44e93 /libpathod/pathod.py | |
parent | 11ac387df2a49d132a08648b6cb5121224924c9d (diff) | |
download | mitmproxy-1a9c1a8c2d6ccedd2248a676a6b3235c8cf86147.tar.gz mitmproxy-1a9c1a8c2d6ccedd2248a676a6b3235c8cf86147.tar.bz2 mitmproxy-1a9c1a8c2d6ccedd2248a676a6b3235c8cf86147.zip |
remove code duplication
Diffstat (limited to 'libpathod/pathod.py')
-rw-r--r-- | libpathod/pathod.py | 37 |
1 files changed, 18 insertions, 19 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: |