On 23 loka, 00:51, Aymeric Augustin
<aymeric.augus...@polytechnique.org> wrote:
> Hello,
>
> While I'm working on HttpResponse, I'd like to resolve two related tickets. 
> Here's my plan for discussion.
>
> #6527 is about normalizing how HttpResponse deals with iterators. For more 
> background, see part 1 of the first email of this thread.
>
> Let's take an HttpResponse instantiated with an iterator.
>
> It's possible not to access the content until the WSGI server iterates on the 
> response. This allows creating streaming responses in Django 1.4. But it's 
> incompatible with most middleware.
>
> Most often middleware will access the content before the response is finally 
> rendered. The first access to response.content works, but subsequent accesses 
> return an empty string.
>
> The fix is easy: consume the content of the iterator and save it in a list 
> for further use. This can be done at two points:
>
> a) In __init__. This is a simple solution advocated by Malcolm in several 
> tickets and it decreases the complexity of HttpResponse (a worthy goal).
>
> It's backwards incompatible because it breaks the streaming scenario 
> described above. We'd have to raise a deprecation warning when the iterator 
> is consumed before the final iteration by the WSGI server, tell people to use 
> StreamingHttpResponse instead, and make the change after two releases.
>
> b) When required. This is the solution implemented in this 
> patch:https://code.djangoproject.com/attachment/ticket/6527/6527-v3.patch
> Even if the target is a), this is a useful workaround for the length of the 
> deprecation period.

I vote consume on __init__ after deprecation period. During the
deprecation period, cache on first access. The behaviour of (b)
"stream except if accessed" doesn't seem useful. If you need streaming
response, then use HttpStreamingResponse, if not, then you don't get
streaming response ever.

How do we actually deprecate this? Would we raise deprecation for any
iterator passed to HttpResponse?

> Finally, I've closed five or six other tickets that were fixed at the same 
> time as #7581 or didn't add anything to the two tickets described above; 
> please tell me if I've missed something.

Thanks for getting streaming responses committed. I tried to work on
this feature but my HTTP/WSGI skills weren't good enough to actually
commit anything...

 - Anssi

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com.
To unsubscribe from this group, send email to 
django-developers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.

Reply via email to