From 495a8b8107dbd4fb511954bcd2322d125addd94e Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Tue, 23 Oct 2012 22:25:38 +0200 Subject: Fixed #6527 -- Provided repeatable content access in HttpResponses instantiated with iterators. --- docs/ref/request-response.txt | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'docs/ref') diff --git a/docs/ref/request-response.txt b/docs/ref/request-response.txt index a4b8e9aa66..c3ba99168d 100644 --- a/docs/ref/request-response.txt +++ b/docs/ref/request-response.txt @@ -569,18 +569,25 @@ Passing iterators Finally, you can pass ``HttpResponse`` an iterator rather than strings. If you use this technique, the iterator should return strings. +Passing an iterator as content to :class:`HttpResponse` creates a +streaming response if (and only if) no middleware accesses the +:attr:`HttpResponse.content` attribute before the response is returned. + .. versionchanged:: 1.5 - Passing an iterator as content to :class:`HttpResponse` creates a - streaming response if (and only if) no middleware accesses the - :attr:`HttpResponse.content` attribute before the response is returned. +This technique is fragile and was deprecated in Django 1.5. If you need the +response to be streamed from the iterator to the client, you should use the +:class:`StreamingHttpResponse` class instead. + +As of Django 1.7, when :class:`HttpResponse` is instantiated with an +iterator, it will consume it immediately, store the response content as a +string, and discard the iterator. - If you want to guarantee that your response will stream to the client, you - should use the new :class:`StreamingHttpResponse` class instead. +.. versionchanged:: 1.5 -If an :class:`HttpResponse` instance has been initialized with an iterator as -its content, you can't use it as a file-like object. Doing so will raise an -exception. +You can now use :class:`HttpResponse` as a file-like object even if it was +instantiated with an iterator. Django will consume and save the content of +the iterator on first access. Setting headers ~~~~~~~~~~~~~~~ -- cgit v1.3