Skip to content
This repository has been archived by the owner on Jan 13, 2021. It is now read-only.

Commit

Permalink
Merge pull request #97 from Lukasa/docupdate
Browse files Browse the repository at this point in the history
Stop using Twitter for documentation examples.
  • Loading branch information
Lukasa committed Mar 13, 2015
2 parents ec7aedc + ae841cb commit 61bcc57
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
4 changes: 2 additions & 2 deletions docs/source/advanced.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ very confident you won't need the connection again anytime soon. However, if
you decide you want to avoid keeping the connection open, you can use the
:class:`HTTP20Connection <hyper.HTTP20Connection>` as a context manager::

with HTTP20Connection('twitter.com:443') as conn:
conn.request('GET', '/')
with HTTP20Connection('http2bin.org') as conn:
conn.request('GET', '/get')
data = conn.getresponse().read()

analyse(data)
Expand Down
4 changes: 2 additions & 2 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ improved speed, lower bandwidth usage, better connection management, and more.

from hyper import HTTP20Connection

conn = HTTP20Connection('twitter.com:443')
conn.request('GET', '/')
conn = HTTP20Connection('http2bin.org:443')
conn.request('GET', '/get')
resp = conn.getresponse()

print(resp.read())
Expand Down
29 changes: 15 additions & 14 deletions docs/source/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ With ``hyper`` installed, you can start making HTTP/2 requests. At this
stage, ``hyper`` can only be used with services that *definitely* support
HTTP/2. Before you begin, ensure that whichever service you're contacting
definitely supports HTTP/2. For the rest of these examples, we'll use
Twitter.
http2bin.org, a HTTP/1.1 and HTTP/2 testing service.

Begin by getting the Twitter homepage::
Begin by getting the homepage::

>>> from hyper import HTTP20Connection
>>> c = HTTP20Connection('twitter.com:443')
>>> c = HTTP20Connection('http2bin.org')
>>> c.request('GET', '/')
1
>>> resp = c.getresponse()
Expand All @@ -75,15 +75,16 @@ come back to it.
Once you've got the data, things continue to behave exactly like
``http.client``::

>>> resp.getheader('content-encoding')
'deflate'
>>> resp.getheader('content-type')
'text/html; charset=utf-8'
>>> resp.getheaders()
[('x-xss-protection', '1; mode=block')...
[('server', 'h2o/1.0.2-alpha1')...
>>> resp.status
200

We know that Twitter has compressed the response body. ``hyper`` will
automatically decompress that body for you, no input required::
If http2bin had compressed the response body. ``hyper`` would automatically
decompress that body for you, no input required. This means you can always get
the body by simply reading it::

>>> body = resp.read()
b'<!DOCTYPE html>\n<!--[if IE 8]><html clas ....
Expand All @@ -100,10 +101,10 @@ the response from any of them, and switch between them using their stream IDs.
For example::

>>> from hyper import HTTP20Connection
>>> c = HTTP20Connection('twitter.com:443')
>>> first = c.request('GET', '/')
>>> second = c.request('GET', '/lukasaoz')
>>> third = c.request('GET', '/about')
>>> c = HTTP20Connection('http2bin.org')
>>> first = c.request('GET', '/get')
>>> second = c.request('POST', '/post', data='key=value')
>>> third = c.request('GET', '/ip')
>>> second_response = c.getresponse(second)
>>> first_response = c.getresponse(first)
>>> third_response = c.getresponse(third)
Expand All @@ -124,8 +125,8 @@ HTTP/2. Once you've worked that out, you can get started straight away::
>>> import requests
>>> from hyper.contrib import HTTP20Adapter
>>> s = requests.Session()
>>> s.mount('https://twitter.com', HTTP20Adapter())
>>> r = s.get('https://twitter.com')
>>> s.mount('https://http2bin.org', HTTP20Adapter())
>>> r = s.get('https://http2bin.org/get')
>>> print(r.status_code)
200

Expand Down

0 comments on commit 61bcc57

Please sign in to comment.