Skip to content
Myr

Merge pull request #826 from hazzadous/develop

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Updated content workflow section of the advanced user docs

authored by Kenneth Reitz · committed by Kenneth Reitz · parents 81897dd, 991b853 · Browse files · 1 file+8 added−14 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+8 added−14 removed

  • other:+8 added−14 removed

1 file+8 added−14 removed

modified:docs/user/advanced.rst+8 added-14 removed
114 unmodified lines
115116Body Content Workflow117---------------------118119By default, when you make a request, the body of the response isn't downloaded immediately. The response headers are downloaded when you make a request, but the content isn't downloaded until you access the :class:`Response.content` attribute.119By default, when you make a request, the body of the response is downloaded immediately. You can override this behavior and defer downloading the response body until you access the :class:`Response.content` attribute with the ``prefetch`` parameter::120121Let's walk through it::122121 tarball_url = 'https://github.com/kennethreitz/requests/tarball/master'124 r = requests.get(tarball_url)122 r = requests.get(tarball_url, prefetch=False)123126The request has been made, but the connection is still open. The response body has not been downloaded yet.124At this point only the response headers have been downloaded and the connection remains open, hence allowing us to make content retrieval conditional::125128::126 if int(r.headers['content-length']) < TOO_LONG:127 content = r.content128 ...129130 r.content130You can further control the workflow by use of the :class:`Response.iter_content` and :class:`Response.iter_lines` methods, or reading from the underlying urllib3 :class:`urllib3.HTTPResponse` at :class:`Response.raw`.131132The content has been downloaded and cached.132Note that in versions prior to 0.13.6 the ``prefetch`` default was set to ``False``.133134You can override this default behavior with the ``prefetch`` parameter::135136 r = requests.get(tarball_url, prefetch=True)137 # Blocks until all of request body has been downloaded.138139134Configuring Requests135--------------------136137Sometimes you may want to configure a request to customize its behavior. To do
424 unmodified lines