@@ -13,25 +13,54 @@ may want to keep your connections alive only as long as you know you'll need
1313them. In HTTP/2 this is generally not something you should do unless you're
1414very confident you won't need the connection again anytime soon. However, if
1515you decide you want to avoid keeping the connection open, you can use the
16- :class: `HTTP20Connection <hyper.HTTP20Connection> ` as a context manager::
16+ :class: `HTTP20Connection <hyper.HTTP20Connection> ` and
17+ :class: `HTTP11Connection <hyper.HTTP11Connection> ` as context managers::
1718
1819 with HTTP20Connection('http2bin.org') as conn:
1920 conn.request('GET', '/get')
2021 data = conn.getresponse().read()
2122
2223 analyse(data)
2324
24- You may not use any :class: `HTTP20Response <hyper.HTTP20Response> ` objects
25- obtained from a connection after that connection is closed. Interacting with
26- these objects when a connection has been closed is considered undefined
27- behaviour.
25+ You may not use any :class: `HTTP20Response <hyper.HTTP20Response> ` or
26+ :class: `HTTP11Response <hyper.HTTP11Response> ` objects obtained from a
27+ connection after that connection is closed. Interacting with these objects when
28+ a connection has been closed is considered undefined behaviour.
29+
30+ Chunked Responses
31+ -----------------
32+
33+ Plenty of APIs return chunked data, and it's often useful to iterate directly
34+ over the chunked data. ``hyper `` lets you iterate over each data frame of a
35+ HTTP/2 response, and each chunk of a HTTP/1.1 response delivered with
36+ ``Transfer-Encoding: chunked ``::
37+
38+ for chunk in response.read_chunked():
39+ do_something_with_chunk(chunk)
40+
41+ There are some important caveats with this iteration: mostly, it's not
42+ guaranteed that each chunk will be non-empty. In HTTP/2, it's entirely legal to
43+ send zero-length data frames, and this API will pass those through unchanged.
44+ Additionally, by default this method will decompress a response that has a
45+ compressed ``Content-Encoding ``: if you do that, each element of the iterator
46+ will no longer be a single chunk, but will instead be whatever the decompressor
47+ returns for that chunk.
48+
49+ If that's problematic, you can set the ``decode_content `` parameter to
50+ ``False `` and, if necessary, handle the decompression yourself::
51+
52+ for compressed_chunk in response.read_chunked(decode_content=False):
53+ decompress(compressed_chunk)
54+
55+ Very easy!
2856
2957Multithreading
3058--------------
3159
32- Currently, ``hyper ``'s :class: `HTTP20Connection <hyper.HTTP20Connection> ` class
33- is **not ** thread-safe. Thread-safety is planned for ``hyper ``'s core objects,
34- but in this early alpha it is not a high priority.
60+ Currently, ``hyper ``'s :class: `HTTP20Connection <hyper.HTTP20Connection> ` and
61+ :class: `HTTP11Connection <hyper.HTTP11Connection> ` classes are **not **
62+ thread-safe. Thread-safety is planned for ``hyper ``'s core objects, but in this
63+ early alpha it is not a high priority.
3564
3665To use ``hyper `` in a multithreaded context the recommended thing to do is to
3766place each connection in its own thread. Each thread should then have a request
@@ -130,7 +159,7 @@ In order to receive pushed resources, the
130159with ``enable_push=True ``.
131160
132161You may retrieve the push promises that the server has sent *so far * by calling
133- :meth: `getpushes () <hyper.HTTP20Connection.getpushes > `, which returns a
162+ :meth: `get_pushes () <hyper.HTTP20Connection.get_pushes > `, which returns a
134163generator that yields :class: `HTTP20Push <hyper.HTTP20Push> ` objects. Note that
135164this method is not idempotent; promises returned in one call will not be
136165returned in subsequent calls. If ``capture_all=False `` is passed (the default),
@@ -143,11 +172,11 @@ the original response, or when also processing the original response in a
143172separate thread (N.B. do not do this; ``hyper `` is not yet thread-safe)::
144173
145174 conn.request('GET', '/')
146- response = conn.getheaders ()
147- for push in conn.getpushes (): # all pushes promised before response headers
175+ response = conn.get_response ()
176+ for push in conn.get_pushes (): # all pushes promised before response headers
148177 print(push.path)
149178 conn.read()
150- for push in conn.getpushes (): # all other pushes
179+ for push in conn.get_pushes (): # all other pushes
151180 print(push.path)
152181
153182To cancel an in-progress pushed stream (for example, if the user already has
0 commit comments