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
Provenance
- Commit
3a9d54f- Tree
feccffb- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent 1
c34d6e8- Parent 2
a29f88c
3 files changed+35 added−2 removed
modified:docs/patterns/streaming.rst+15 added
6 unmodified lines7 roundtrip to the filesystem?8 9 The answer is by using generators and direct responses.10 11+HTTP Response Behavior12+----------------------13+14+**Headers cannot be changed after the streaming response starts.**15+16+When using streaming, it's important to be aware of the order than an HTTP17+response is sent. All headers must be sent first, then the body. More headers18+cannot be sent after the body has begun. Therefore, you must make sure all19+headers are set before starting the response, outside the generator.20+21+In particular, if the generator will access ``session``, be sure to do so in the22+view as well so that the ``Vary: cookie`` header will be set. Do not modify the23+session in the generator, as the ``Set-Cookie`` header will already be sent.24+25+26 Basic Usage27 -----------28 29 This is a basic view function that generates a lot of CSV data on the fly.71 unmodified linesmodified:docs/templating.rst+8 added-2 removed
249 unmodified lines250 def timeline():251 return stream_template("timeline.html")252 253 These functions automatically apply the254-:func:`~flask.stream_with_context` wrapper if a request is active, so255-that 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 the256+template.257+258+More headers cannot be sent after the body has begun. Therefore, you must259+make sure all headers are set before starting the response. In particular,260+if the template will access ``session``, be sure to do so in the view as261+well so that the ``Vary: cookie`` header will be set.modified:src/flask/helpers.py+12 added
66 unmodified lines67 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.70 71+ .. warning::72+73+ 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.76+77+ 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.82+83 Use it as a decorator on a generator function:84 85 .. code-block:: python86 596 unmodified lines