@@ -55,12 +55,12 @@ With ``hyper`` installed, you can start making HTTP/2 requests. At this
5555stage, ``hyper `` can only be used with services that *definitely * support
5656HTTP/2. Before you begin, ensure that whichever service you're contacting
5757definitely supports HTTP/2. For the rest of these examples, we'll use
58- Twitter .
58+ http2bin.org, a HTTP/1.1 and HTTP/2 testing service .
5959
60- Begin by getting the Twitter homepage::
60+ Begin by getting the homepage::
6161
6262 >>> from hyper import HTTP20Connection
63- >>> c = HTTP20Connection('twitter.com:443 ')
63+ >>> c = HTTP20Connection('http2bin.org ')
6464 >>> c.request('GET', '/')
6565 1
6666 >>> resp = c.get_response()
@@ -76,15 +76,16 @@ come back to it.
7676
7777Once you've got the data, things diverge a little bit::
7878
79- >>> resp.getheader ('content-encoding ')
80- 'deflate '
79+ >>> resp.header ('content-type ')
80+ 'text/html; charset=utf-8 '
8181 >>> resp.headers
82- HTTPHeaderMap([(b'x-xss-protection ', b'1; mode=block ')...
82+ HTTPHeaderMap([('server ', 'h2o/1.0.2-alpha1 ')...
8383 >>> resp.status
8484 200
8585
86- We know that Twitter has compressed the response body. ``hyper `` will
87- automatically decompress that body for you, no input required::
86+ If http2bin had compressed the response body. ``hyper `` would automatically
87+ decompress that body for you, no input required. This means you can always get
88+ the body by simply reading it::
8889
8990 >>> body = resp.read()
9091 b'<!DOCTYPE html>\n<!--[if IE 8]><html clas ....
@@ -101,13 +102,13 @@ the response from any of them, and switch between them using their stream IDs.
101102For example::
102103
103104 >>> from hyper import HTTP20Connection
104- >>> c = HTTP20Connection('twitter.com:443 ')
105- >>> first = c.request('GET', '/')
106- >>> second = c.request('GET ', '/lukasaoz ')
107- >>> third = c.request('GET', '/about ')
108- >>> second_response = c.get_response (second)
109- >>> first_response = c.get_response (first)
110- >>> third_response = c.get_response (third)
105+ >>> c = HTTP20Connection('http2bin.org ')
106+ >>> first = c.request('GET', '/get ')
107+ >>> second = c.request('POST ', '/post', data='key=value ')
108+ >>> third = c.request('GET', '/ip ')
109+ >>> second_response = c.getresponse (second)
110+ >>> first_response = c.getresponse (first)
111+ >>> third_response = c.getresponse (third)
111112
112113``hyper `` will ensure that each response is matched to the correct request.
113114
@@ -160,8 +161,8 @@ HTTP/2. Once you've worked that out, you can get started straight away::
160161 >>> import requests
161162 >>> from hyper.contrib import HTTP20Adapter
162163 >>> s = requests.Session()
163- >>> s.mount('https://twitter.com ', HTTP20Adapter())
164- >>> r = s.get('https://twitter.com ')
164+ >>> s.mount('https://http2bin.org ', HTTP20Adapter())
165+ >>> r = s.get('https://http2bin.org/get ')
165166 >>> print(r.status_code)
166167 200
167168
@@ -173,8 +174,8 @@ you away from HTTP/2. Make sure you install the adapter for all the hostnames
173174you're interested in::
174175
175176 >>> a = HTTP20Adapter()
176- >>> s.mount('https://twitter.com ', a)
177- >>> s.mount('https://www.twitter.com ', a)
177+ >>> s.mount('https://http2bin.org ', a)
178+ >>> s.mount('https://www.http2bin.org ', a)
178179
179180.. _requests : http://python-requests.org/
180181
0 commit comments