aboutsummaryrefslogtreecommitdiffstats
path: root/pathod
diff options
context:
space:
mode:
authorShadab Zafar <dufferzafar0@gmail.com>2016-07-03 18:03:34 +0530
committerShadab Zafar <dufferzafar0@gmail.com>2016-07-03 18:03:34 +0530
commitd3611777539471e53d4fdedf352ed755a4092415 (patch)
tree8e96db0df03a43761ded4f18aec7146a0c0fb034 /pathod
parentf70fd1b4b6204195ad85669abe8d275a0e97fdf2 (diff)
downloadmitmproxy-d3611777539471e53d4fdedf352ed755a4092415.tar.gz
mitmproxy-d3611777539471e53d4fdedf352ed755a4092415.tar.bz2
mitmproxy-d3611777539471e53d4fdedf352ed755a4092415.zip
h2: move header parsing to netlib
Diffstat (limited to 'pathod')
-rw-r--r--pathod/protocols/http2.py46
1 files changed, 7 insertions, 39 deletions
diff --git a/pathod/protocols/http2.py b/pathod/protocols/http2.py
index c8728940..d94cd981 100644
--- a/pathod/protocols/http2.py
+++ b/pathod/protocols/http2.py
@@ -7,8 +7,7 @@ import hyperframe.frame
from hpack.hpack import Encoder, Decoder
from netlib import utils, strutils
-from netlib.http import url
-from netlib.http.http2 import framereader
+from netlib.http import http2
import netlib.http.headers
import netlib.http.response
import netlib.http.request
@@ -101,46 +100,15 @@ class HTTP2StateProtocol(object):
timestamp_end = time.time()
- authority = headers.get(':authority', b'')
- method = headers.get(':method', 'GET')
- scheme = headers.get(':scheme', 'https')
- path = headers.get(':path', '/')
-
- headers.clear(":method")
- headers.clear(":scheme")
- headers.clear(":path")
-
- host = None
- port = None
-
- if path == '*' or path.startswith("/"):
- first_line_format = "relative"
- elif method == 'CONNECT':
- first_line_format = "authority"
- if ":" in authority:
- host, port = authority.split(":", 1)
- else:
- host = authority
- else:
- first_line_format = "absolute"
- # FIXME: verify if path or :host contains what we need
- scheme, host, port, _ = url.parse(path)
- scheme = scheme.decode('ascii')
- host = host.decode('ascii')
-
- if host is None:
- host = 'localhost'
- if port is None:
- port = 80 if scheme == 'http' else 443
- port = int(port)
+ first_line_format, method, scheme, host, port, path = http2.parse_headers(headers)
request = netlib.http.request.Request(
first_line_format,
- method.encode('ascii'),
- scheme.encode('ascii'),
- host.encode('ascii'),
+ method,
+ scheme,
+ host,
port,
- path.encode('ascii'),
+ path,
b"HTTP/2.0",
headers,
body,
@@ -286,7 +254,7 @@ class HTTP2StateProtocol(object):
def read_frame(self, hide=False):
while True:
- frm = framereader.http2_read_frame(self.tcp_handler.rfile)
+ frm = http2.framereader.http2_read_frame(self.tcp_handler.rfile)
if not hide and self.dump_frames: # pragma no cover
print(frm.human_readable("<<"))