aboutsummaryrefslogtreecommitdiffstats
path: root/netlib/utils.py
diff options
context:
space:
mode:
authorThomas Kriechbaumer <Kriechi@users.noreply.github.com>2016-02-01 20:28:14 +0100
committerThomas Kriechbaumer <Kriechi@users.noreply.github.com>2016-02-01 20:28:14 +0100
commit81b32cf42629dcbe8f59633dcb9b62816b781968 (patch)
treea0aa45506d52dc1cd273b77997022d04e7338f12 /netlib/utils.py
parent1e203401261ab6b24ae193f81dc4256854de13d8 (diff)
parente98c729bb9b0d3debde6f61c948108bdc9dbafbe (diff)
downloadmitmproxy-81b32cf42629dcbe8f59633dcb9b62816b781968.tar.gz
mitmproxy-81b32cf42629dcbe8f59633dcb9b62816b781968.tar.bz2
mitmproxy-81b32cf42629dcbe8f59633dcb9b62816b781968.zip
Merge pull request #116 from Kriechi/hyperframe
migrate to hyperframe
Diffstat (limited to 'netlib/utils.py')
-rw-r--r--netlib/utils.py21
1 files changed, 19 insertions, 2 deletions
diff --git a/netlib/utils.py b/netlib/utils.py
index 66225897..1c1b617a 100644
--- a/netlib/utils.py
+++ b/netlib/utils.py
@@ -2,12 +2,12 @@ from __future__ import absolute_import, print_function, division
import os.path
import re
import string
+import codecs
import unicodedata
-
import six
from six.moves import urllib
-
+import hyperframe
def always_bytes(unicode_or_bytes, *encode_args):
if isinstance(unicode_or_bytes, six.text_type):
@@ -366,3 +366,20 @@ def multipartdecode(headers, content):
r.append((key, value))
return r
return []
+
+
+def http2_read_raw_frame(rfile):
+ header = rfile.safe_read(9)
+ length = int(codecs.encode(header[:3], 'hex_codec'), 16)
+
+ if length == 4740180:
+ raise ValueError("Length field looks more like HTTP/1.1: %s" % rfile.peek(20))
+
+ body = rfile.safe_read(length)
+ return [header, body]
+
+def http2_read_frame(rfile):
+ header, body = http2_read_raw_frame(rfile)
+ frame, length = hyperframe.frame.Frame.parse_frame_header(header)
+ frame.parse_body(memoryview(body))
+ return frame