Skip to content
Myr

Merge branch 'stable'

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

authored by David Lord · committed by David Lord · parents c34d6e8, a29f88c · Browse files · 3 files+35 added−2 removed
This commit

State

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

Diff stats

3 files+35 added−2 removed

  • other:+35 added−2 removed

3 files+35 added−2 removed

modified:docs/patterns/streaming.rst+15 added
6 unmodified lines
7roundtrip to the filesystem?89The answer is by using generators and direct responses.1011HTTP Response Behavior12----------------------1314**Headers cannot be changed after the streaming response starts.**1516When using streaming, it's important to be aware of the order than an HTTP17response is sent. All headers must be sent first, then the body. More headers18cannot be sent after the body has begun. Therefore, you must make sure all19headers are set before starting the response, outside the generator.2021In particular, if the generator will access ``session``, be sure to do so in the22view as well so that the ``Vary: cookie`` header will be set. Do not modify the23session in the generator, as the ``Set-Cookie`` header will already be sent.242526Basic Usage27-----------2829This is a basic view function that generates a lot of CSV data on the fly.
71 unmodified lines
modified:docs/templating.rst+8 added-2 removed
249 unmodified lines
250 def timeline():251 return stream_template("timeline.html")252253These functions automatically apply the254:func:`~flask.stream_with_context` wrapper if a request is active, so255that it remains available in the template.254:func:`~flask.stream_with_context` wrapper if a request is active, so that255:data:`.request`, :data:`.session`, and :data:`.g` remain available in the256template.257258More headers cannot be sent after the body has begun. Therefore, you must259make sure all headers are set before starting the response. In particular,260if the template will access ``session``, be sure to do so in the view as261well so that the ``Vary: cookie`` header will be set.
modified:src/flask/helpers.py+12 added
66 unmodified lines
67 request context. This keeps :data:`.request`, :data:`.session`, and :data:`.g`68 available, even though at the point the generator runs the request context69 will typically have ended.7071 .. warning::7273 Due to the following caveat, it is often safer to pass the data you74 need as arguments to the generator, rather than relying on the context75 objects.7677 More headers cannot be sent after the body has begun. Therefore, you must78 make sure all headers are set before starting the response. In particular,79 if the generator will access ``session``, be sure to do so in the view as80 well so that the ``Vary: cookie`` header will be set. Do not modify the81 session in the generator, as the ``Set-Cookie`` header will already be sent.8283 Use it as a decorator on a generator function:8485 .. code-block:: python86
596 unmodified lines