Skip to content

Instantly share code, notes, and snippets.

@Lukasa
Last active August 29, 2015 14:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Lukasa/7bde67d6d84254dcfc2f to your computer and use it in GitHub Desktop.
Save Lukasa/7bde67d6d84254dcfc2f to your computer and use it in GitHub Desktop.
Example of hyper code demonstrating incorrect response from Google

Google's server is providing an incorrect pseudo-header field. Their response contains the pseudo-header field ':status' with the value '302 Found', in violation of the draft. The relevant section is Section 8.1.2.4 of the h2-14 draft, which reads:

A single ":status" header field is defined that carries the HTTP status code field (see [RFC7231], Section 6). This header field MUST be included in all responses, otherwise the response is malformed (Section 8.1.2.6).

HTTP/2 does not define a way to carry the version or reason phrase that is included in an HTTP/1.1 status line.

Further evaluation of the HPACK static table also indicates that the word 'Found' should not be present in this header field.

INFO:hyper.http20.connection:Sending frame SettingsFrame on stream 0
INFO:hyper.http20.connection:Received frame SettingsFrame on stream 0
INFO:hyper.http20.connection:Sending frame SettingsFrame on stream 0
DEBUG:hyper.http20.hpack:HPACK encoding [(':method', 'GET'), (':scheme', 'https'), (':authority', 'google.com'), (':path', '/'), ('user-agent', 'hyper/0.1.0 CPython/3.4')]
DEBUG:hyper.http20.hpack:Adding (b':method', b'GET') to the header table
DEBUG:hyper.http20.hpack:Encoding 2 with 7 bits.
DEBUG:hyper.http20.hpack:Adding (b':scheme', b'https') to the header table
DEBUG:hyper.http20.hpack:Encoding 7 with 7 bits.
DEBUG:hyper.http20.hpack:Adding (b':authority', b'google.com') to the header table
DEBUG:hyper.http20.hpack:Encoding 1 with 4 bits.
DEBUG:hyper.http20.hpack:Encoding 7 with 7 bits.
DEBUG:hyper.http20.hpack:Adding (b':path', b'/') to the header table
DEBUG:hyper.http20.hpack:Encoding 4 with 7 bits.
DEBUG:hyper.http20.hpack:Adding (b'user-agent', b'hyper/0.1.0 CPython/3.4') to the header table
DEBUG:hyper.http20.hpack:Encoding 58 with 4 bits.
DEBUG:hyper.http20.hpack:Encoding 17 with 7 bits.
DEBUG:hyper.http20.hpack:Encoded header block to b'\x82\x87\x01\x87\x98\xe7\x9a\x82\xaeC\xd3\x84\x0f+\x91\x9f\xd5e\xb1\x80.\x15\xc0\xa5\xed~\x939\xeaa\x95\xda'
INFO:hyper.http20.connection:Sending frame HeadersFrame on stream 1
INFO:hyper.http20.connection:Received frame WindowUpdateFrame on stream 0
INFO:hyper.http20.connection:Received frame SettingsFrame on stream 0
INFO:hyper.http20.connection:Received frame HeadersFrame on stream 1
DEBUG:hyper.http20.hpack:Decoding b'H\x87d\x02S\t\xed\xaaO@\x8d\x1d\t-\x95\r%Z\xbb\x0e\x93\x90\xf4\x7f\x86i\xa6nv\xb4\xc4X\x85\xae\xc3w\x1aK\\\x82\x13\x82_\x92I|\xa5\x89\xd3M\x1fj\x12q\xd8\x82\xa6\x0e\x1b\xf0\xac\xf7a\x96\xdfi~\x94\x00\x94\xdcZ\xd4\x10\x02\xd2\x80z\xe0Cq\xb7\xd4\xc5\xa3\x7fn\xaf\x9d)\xad\x17\x18c\xc7\x8f\x0b\xccs\xcdAW!\xd7\xb7\xab\x1f\xe4\xd2\x96+$\x80\x96|\x14\xd0{e\x18x\xe6\xab-\xd7\xbdv{\xc1j\xad\xab\xdc\xefCv\x86\xc5\x87\x03\x02\\\x1f'
DEBUG:hyper.http20.hpack:Decoded 8 consuming 1 bytes.
DEBUG:hyper.http20.hpack:Decoded 7 consuming 1 bytes.
DEBUG:hyper.http20.hpack:Decoded (b':status', b'302 Found'), consumed 1, indexed True
DEBUG:hyper.http20.hpack:Decoded 13 consuming 1 bytes.
DEBUG:hyper.http20.hpack:Decoded 6 consuming 1 bytes.
DEBUG:hyper.http20.hpack:Decoded (b'alternate-protocol', b'443:quic'), consumed 1, indexed True
DEBUG:hyper.http20.hpack:Decoded 24 consuming 1 bytes.
DEBUG:hyper.http20.hpack:Decoded 5 consuming 1 bytes.
DEBUG:hyper.http20.hpack:Decoded (b'cache-control', b'private'), consumed 1, indexed True
DEBUG:hyper.http20.hpack:Decoded 28 consuming 1 bytes.
DEBUG:hyper.http20.hpack:Decoded 2 consuming 1 bytes.
DEBUG:hyper.http20.hpack:Decoded (b'content-length', b'262'), consumed 1, indexed True
DEBUG:hyper.http20.hpack:Decoded 31 consuming 1 bytes.
DEBUG:hyper.http20.hpack:Decoded 18 consuming 1 bytes.
DEBUG:hyper.http20.hpack:Decoded (b'content-type', b'text/html; charset=UTF-8'), consumed 1, indexed True
DEBUG:hyper.http20.hpack:Decoded 33 consuming 1 bytes.
DEBUG:hyper.http20.hpack:Decoded 22 consuming 1 bytes.
DEBUG:hyper.http20.hpack:Decoded (b'date', b'Tue, 02 Sep 2014 08:11:59 GMT'), consumed 1, indexed True
DEBUG:hyper.http20.hpack:Decoded 46 consuming 1 bytes.
DEBUG:hyper.http20.hpack:Decoded 47 consuming 1 bytes.
DEBUG:hyper.http20.hpack:Decoded (b'location', b'https://www.google.co.uk/?gfe_rd=cr&ei=z3sFVKnJB8yq8wenp4CYCA'), consumed 1, indexed True
DEBUG:hyper.http20.hpack:Decoded 54 consuming 1 bytes.
DEBUG:hyper.http20.hpack:Decoded 6 consuming 1 bytes.
DEBUG:hyper.http20.hpack:Decoded (b'server', b'GFE/2.0'), consumed 1, indexed True
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python34\lib\site-packages\hyper\http20\connection.py", line 171, in getresponse
return HTTP20Response(stream.getheaders(), stream)
File "C:\Python34\lib\site-packages\hyper\http20\response.py", line 108, in __init__
self.status = int(status)
ValueError: invalid literal for int() with base 10: '302 Found'
import hyper
import logging
logging.basicConfig(filename='http2.txt', level=logging.DEBUG)
c = hyper.HTTP20Connection('google.com', 443)
c.request('GET', '/', headers={'User-Agent': 'hyper/0.1.0 CPython/3.4.3'})
r = c.getresponse()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment