I think I prefer keeping HttpResponse and HttpResponseStreaming
separate. Using the latter indicates explicitly that the user wants to
send a streaming response and disable any middleware that doesn't
explicitly support it. Using the former should always consume any
content passed to it so that middleware doesn't have to know or care
what type of content was passed to the HttpResponse.

This way only specific middleware are required to opt-in to support
streaming responses, rather than requiring all middleware to
repetitively examine the content type and opt-out to avoid breaking
streaming responses.

It also keeps the interface simple. HttpResponse.content will always
be a string, HttpResponseStreaming.content will always be an iterator,
and HttpResponse classes will only need to expose one attribute for
content either way.

And it's more explicit. Django will only disable middleware that
doesn't explicitly assert that it works with HttpResponseStreaming,
and only when the user explicitly creates an HttpResponseStreaming
object.

Regarding `hasattr` vs `isinstance`, the latter should also work with
subclasses and has the benefit of detecting only HttpResponseStreaming
(and derivative) objects, not just any object with a
`content_generator` attribute. If we use `isinstance`, the
HttpResponseStreaming class won't even need a `content_generator`
attribute, nor will middleware need to poke around in it's internals
to replace the content with a new generator.

Regarding the Content-Length header, HttpResponse should always set it
because the content will always be a string, but HttpResponseStreaming
should never set it because we can never know the length without
consuming the content.

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

Reply via email to