One thing I'm curious about here is the HTTP Content-Length header.
It's late and I'm tired and cranky, so I may have missed it, but
outside of the infrastructure for runserver I can't find any place
where Django reliably sets it on outgoing responses. And the WSGI
spec's stance is that if the client supports it, a missing
Content-Length can be taken as a cue to chunk the response
(unfortunately WSGI forbids the one HTTP header that truly serves as a
reliable source of information for this).
If we could get some sort of mechanism for having HttpResponse set the
Content-Length header (or not) as needed, we'd have something which
would be a lot more consistent, and not just at the Django level.
Middlewares which want to look at the response body could check for
the header: if it's there the response is safe to
inspect/consume/fiddle with, and if it's missing the response is not
safe to inspect/consume/fiddle with. Servers would still be free to do
what they like, and presumably people who want to stream out a
response piece by piece will use servers which implement the behavior
permitted by WSGI. This sidesteps your question about type checking,
and uses a mechanism which is at least semi-blessed by the gateway
protocol, so it has interoperability benefits beyond Django middleware
classes.
--
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."