I'm loading a particularly large JSON string that is dynamically generated by PHP. To provide some feedback to the user, I want to show download progress.
I have the code figured out, and it works fine for static content such as images, JS files, etc. However, it doesn't seem to work for dynamic files.
This makes sense, since the dynamic files don't have predictable content length, but even if I add this in PHP:
ob_start(function($c) {
header("Content-Length: ".strlen($c));
return $c;
});
It still does not send the header (but if I add any other header it works fine).
Is there any way to force Apache to send the Content-Length
header? Currently my only alternative is to save the output to a temporary file and redirect to it instead. This would work, but it's kind of messy so I'd rather avoid it if possible.
When making a POST request, HTTP clients typically automatically add a Content-Length header based on the size of the data supplied and a Content-Type header based on the type of data being transferred.
The Content-Length is optional in an HTTP request. For a GET or DELETE the length must be zero. For POST, if Content-Length is specified and it does not match the length of the message-line, the message is either truncated, or padded with nulls to the specified length.
The Content-Length header is mandatory for messages with entity bodies, unless the message is transported using chunked encoding. Content-Length is needed to detect premature message truncation when servers crash and to properly segment messages that share a persistent connection.
I had similar problem but in my case Content-Length header wasn't sent by Apache because the response was gzip compressed. When I disable compression the Content-Length was calculated and sent properly.
Below is htaccess setting to disable gzip compression for swf file only
<FilesMatch "\.swf$">
SetEnv no-gzip 1
</FilesMatch>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With