@@ -59,20 +59,20 @@ http2bin.org, a HTTP/1.1 and HTTP/2 testing service.
5959
6060Begin by getting the homepage::
6161
62- >>> from hyper import HTTP20Connection
63- >>> c = HTTP20Connection ('http2bin.org')
62+ >>> from hyper import HTTPConnection
63+ >>> c = HTTPConnection ('http2bin.org')
6464 >>> c.request('GET', '/')
6565 1
6666 >>> resp = c.get_response()
6767
6868Used in this way, ``hyper `` behaves exactly like ``http.client ``. You can make
6969sequential requests using the exact same API you're accustomed to. The only
7070difference is that
71- :meth: `HTTP20Connection .request() <hyper.HTTP20Connection .request> ` returns a
72- value, unlike the equivalent ``http.client `` function. The return value is the
73- HTTP/2 *stream identifier *. If you're planning to use ``hyper `` in this very
74- simple way, you can choose to ignore it, but it's potentially useful. We'll
75- come back to it.
71+ :meth: `HTTPConnection .request() <hyper.HTTPConnection .request> ` may return a
72+ value, unlike the equivalent ``http.client `` function. If present, the return
73+ value is the HTTP/2 *stream identifier *. If you're planning to use ``hyper ``
74+ in this very simple way, you can choose to ignore it, but it's potentially
75+ useful. We'll come back to it.
7676
7777Once you've got the data, things diverge a little bit::
7878
@@ -101,8 +101,8 @@ the response from any of them, and switch between them using their stream IDs.
101101
102102For example::
103103
104- >>> from hyper import HTTP20Connection
105- >>> c = HTTP20Connection ('http2bin.org')
104+ >>> from hyper import HTTPConnection
105+ >>> c = HTTPConnection ('http2bin.org')
106106 >>> first = c.request('GET', '/get')
107107 >>> second = c.request('POST', '/post', body='key=value')
108108 >>> third = c.request('GET', '/ip')
@@ -112,40 +112,18 @@ For example::
112112
113113``hyper `` will ensure that each response is matched to the correct request.
114114
115- Making Your First HTTP/1.1 Request
116- -----------------------------------
115+ Abstraction
116+ -----------
117117
118- With ``hyper `` installed, you can start making HTTP/2 requests. At this
119- stage, ``hyper `` can only be used with services that *definitely * support
120- HTTP/2. Before you begin, ensure that whichever service you're contacting
121- definitely supports HTTP/2. For the rest of these examples, we'll use
122- Twitter.
123-
124- You can also use ``hyper `` to make HTTP/1.1 requests. The code is very similar.
125- For example, to get the Twitter homepage::
126-
127- >>> from hyper import HTTP11Connection
128- >>> c = HTTP11Connection('twitter.com:443')
129- >>> c.request('GET', '/')
130- >>> resp = c.get_response()
131-
132- The key difference between HTTP/1.1 and HTTP/2 is that when you make HTTP/1.1
133- requests you do not get a stream ID. This is, of course, because HTTP/1.1 does
134- not have streams.
118+ When you use the :class: `HTTPConnection <hyper.HTTPConnection> ` object, you
119+ don't have to know in advance whether your service supports HTTP/2 or not. If
120+ it doesn't, ``hyper `` will transparently fall back to HTTP/1.1.
135121
136- Things behave exactly like they do in the HTTP/2 case, right down to the data
137- reading::
122+ You can tell the difference: if :meth: `request <hyper.HTTPConnection.request> `
123+ returns a stream ID, then the connection is using HTTP/2: if it returns
124+ ``None ``, then HTTP/1.1 is being used.
138125
139- >>> resp.headers['content-encoding']
140- [b'deflate']
141- >>> resp.headers
142- HTTPHeaderMap([(b'x-xss-protection', b'1; mode=block')...
143- >>> resp.status
144- 200
145- >>> body = resp.read()
146- b'<!DOCTYPE html>\n<!--[if IE 8]><html clas ....
147-
148- That's all it takes.
126+ Generally, though, you don't need to care.
149127
150128Requests Integration
151129--------------------
@@ -155,8 +133,7 @@ requests doesn't support HTTP/2 though. To rectify that oversight, ``hyper``
155133provides a transport adapter that can be plugged directly into Requests, giving
156134it instant HTTP/2 support.
157135
158- All you have to do is identify a host that you'd like to communicate with over
159- HTTP/2. Once you've worked that out, you can get started straight away::
136+ Using ``hyper `` with requests is super simple::
160137
161138 >>> import requests
162139 >>> from hyper.contrib import HTTP20Adapter
@@ -169,14 +146,6 @@ HTTP/2. Once you've worked that out, you can get started straight away::
169146This transport adapter is subject to all of the limitations that apply to
170147``hyper ``, and provides all of the goodness of requests.
171148
172- A quick warning: some hosts will redirect to new hostnames, which may redirect
173- you away from HTTP/2. Make sure you install the adapter for all the hostnames
174- you're interested in::
175-
176- >>> a = HTTP20Adapter()
177- >>> s.mount('https://http2bin.org', a)
178- >>> s.mount('https://www.http2bin.org', a)
179-
180149.. _requests : http://python-requests.org/
181150
182151HTTPie Integration
0 commit comments