python-hyper / hyper

HTTP/2 for Python.
http://hyper.rtfd.org/en/latest/
MIT License
1.05k stars 191 forks source link

Documentation proposes an example that does not work. #286

Closed Lukasa closed 7 years ago

Lukasa commented 7 years ago

The quickstart guide includes this example:

>>> from hyper import HTTPConnection
>>> c = HTTPConnection('http2bin.org')
>>> first = c.request('GET', '/get', headers={'key': 'value'})
>>> second = c.request('POST', '/post', body=b'hello')
>>> third = c.request('GET', '/ip')
>>> second_response = c.get_response(second)
>>> first_response = c.get_response(first)
>>> third_response = c.get_response(third)

This example is fundamentally flawed, because before you know you have a HTTP/2 connection you cannot safely send multiple requests down it. In the first instance, we can fix this by using port 443 in the constructor. We may also want to add a formalised API for working out what protocol version you're working with.