[Fixed]-Django send content-length to StreamingHttpResponse from a Popen process


If I understood your question correctly you need to send Content-Length header while streaming the response via StreamingHttpResponse. If that’s the case, then it is not possible and it is explicitly stated in StreamingHttpResponse documentation:

StreamingHttpResponse should only be used in situations where it is
absolutely required that the whole content isn’t iterated before
transferring the data to the client. Because the content can’t be
accessed, many middlewares can’t function normally. For example the
ETag and Content-Length headers can’t be generated for streaming

To my mind transcoding an audio file during request processing is not a good idea as you can exhaust all the request handlers this way. Instead I would use some kind of background processing, for example Celery.

Leave a comment