aboutsummaryrefslogtreecommitdiffstats
path: root/netlib/http/http2
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 /netlib/http/http2
parentf70fd1b4b6204195ad85669abe8d275a0e97fdf2 (diff)
downloadmitmproxy-d3611777539471e53d4fdedf352ed755a4092415.tar.gz
mitmproxy-d3611777539471e53d4fdedf352ed755a4092415.tar.bz2
mitmproxy-d3611777539471e53d4fdedf352ed755a4092415.zip
h2: move header parsing to netlib
Diffstat (limited to 'netlib/http/http2')
-rw-r--r--netlib/http/http2/__init__.py2
-rw-r--r--netlib/http/http2/utils.py37
2 files changed, 39 insertions, 0 deletions
diff --git a/netlib/http/http2/__init__.py b/netlib/http/http2/__init__.py
index 6a979a0d..60064190 100644
--- a/netlib/http/http2/__init__.py
+++ b/netlib/http/http2/__init__.py
@@ -1,6 +1,8 @@
from __future__ import absolute_import, print_function, division
from netlib.http.http2 import framereader
+from netlib.http.http2.utils import parse_headers
__all__ = [
"framereader",
+ "parse_headers",
]
diff --git a/netlib/http/http2/utils.py b/netlib/http/http2/utils.py
new file mode 100644
index 00000000..4d5f580c
--- /dev/null
+++ b/netlib/http/http2/utils.py
@@ -0,0 +1,37 @@
+from netlib.http import url
+
+
+def parse_headers(headers):
+ authority = headers.get(':authority', b'')
+ method = headers.get(':method', b'GET')
+ scheme = headers.get(':scheme', b'https')
+ path = headers.get(':path', b'/')
+
+ headers.clear(":method")
+ headers.clear(":scheme")
+ headers.clear(":path")
+
+ host = None
+ port = None
+
+ if path == b'*' or path.startswith(b"/"):
+ first_line_format = "relative"
+ elif method == b'CONNECT': # pragma: no cover
+ raise NotImplementedError("CONNECT over HTTP/2 is not implemented.")
+ else: # pragma: no cover
+ first_line_format = "absolute"
+ # FIXME: verify if path or :host contains what we need
+ scheme, host, port, _ = url.parse(path)
+
+ if authority:
+ host, _, port = authority.partition(b':')
+
+ if not host:
+ host = b'localhost'
+
+ if not port:
+ port = 443 if scheme == b'https' else 80
+
+ port = int(port)
+
+ return first_line_format, method, scheme, host, port, path