You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Ben Johnson <be...@indietorrent.org> on 2012/09/12 19:16:12 UTC
[users@httpd] gzipping via mod_deflate, the DeflateBufferSize, the Content-Length
header, and download progress in Web browsers
I have a "download page" that serves various types of content (PDFs, ZIP
files, images, etc.) via a PHP script that is executed atop Apache.
Whenever I enable GZIP compression on this page, via mod_deflate, Web
browsers do not show the total file size to be downloaded, presumably
because Apache is chunking the reply and the Content-Length header is
very small, e.g., 20 (even when the binary file size is several MB).
I came to this conclusion after finding these two related threads:
http://serverfault.com/questions/183843/content-length-not-sent-when-gzip-compression-enabled-in-apache
http://serverfault.com/questions/366996/how-can-the-apache-2-2-deflate-module-length-limit-be-increased
I'm able to reproduce the issue at will, and enabling mod_deflate
definitely causes the Content-Length header value to change to a low
value (and Web browser download progress to "break").
Perhaps this is "expected behavior". If that is the case, then I'm
wondering how to address the behavior; users can't live without a
progress bar for files this large (and I don't blame them).
Is it advisable to set the DeflateBufferSize directive to some
ridiculously large value? That just... "feels wrong". Some of the
file-downloads are 2GB in size, and I hesitate to set DeflateBufferSize
to 2097152000.
Would it be better to disable GZIP compression for all URLs within the
/download/ (for example) directory?
Or perhaps for certain file-types? Because I tried that with the
following, but it seems not to have any effect (I believe this example
to be directly from the Apache documentation, with a few additional
extensions added):
<Location />
SetOutputFilter DEFLATE
# Don't compress images (or other files that are already compressed)
SetEnvIfNoCase Request_URI \
\.(?:gif|jpe?g|png|zip|7z|rar|sit?x|mp3|flac|ogg|pdf)$ no-gzip dont-vary
# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary
</Location>
The URLs in question take the following format:
https://localhost/public/download/My%20Installer.zip
Also, I am setting the Content-Type header appropriately, e.g., to
"application/zip", given the above URL.
So, I'm not sure why that rule don't seem to be effective.
I would be happy to hear anybody's thoughts or suggestions.
Thank you for taking the time,
-Ben
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] gzipping via mod_deflate, the DeflateBufferSize,
the Content-Length header, and download progress in Web browsers
Posted by Ben Johnson <be...@indietorrent.org>.
On 9/26/2012 12:39 PM, Eric Covener wrote:
>> Is there any chance that the SetEnvIfNoCase directive is not being
>> satisfied due to the mod_rewrite rules that I'm using?
>
> There's always a way for things to go wrong with mod_rewrite.
>
> SetEnvIf would run both before and after your rewrite on both the
> rewritten and un-rewritten URL, and environment variables would not
> really live from the first pass to the second which is I think what
> you're counting on. I suggest adding a rule to set no-gzip based on
> the query string you'll redirect to.
Given that the original *and* rewritten URL both end with a file
extension, shouldn't the SetEnvIf directive be effective in either case?
The original URLs take the following format:
https://localhost/public/download/My%20Installer.zip
The following mod_rewrite rules are applied:
# Rewrite URIs of the form 'index.php?q=x' (except for real
files/directories):
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
(Note that these download files are NOT real files; they are passed to
the browser via PHP script; so, the mod_rewrite rules are applied.)
The resultant URLs take the following format:
https://localhost/public/index.php?q=download/My%20Installer.zip
After the rewriting is done, the relevant Apache server environment
variables look like this:
'REQUEST_METHOD' => string 'GET' (length=3)
'QUERY_STRING' => string 'q=download/My Installer.zip' (length=68)
'REQUEST_URI' => string '/public/download/My%20Installer.zip' (length=87)
'SCRIPT_NAME' => string '/public/index.php' (length=20)
'PHP_SELF' => string '/public/index.php' (length=20)
Given the above, shouldn't this rule be effective?
# Don't compress images (or other files that are already compressed)
SetEnvIfNoCase Request_URI \
\.(?:gif|jpe?g|png|zip|7z|rar|sit?x|mp3|flac|ogg|pdf)$ no-gzip dont-vary
> Before you chase that, you can just log it the internal var with
> %{no-gzip}e and %{REDIRECT_no-gzip}e
Forgive me for being dense here, but do you mind restating this last
bit? It seems like there's a typo. Are you suggesting that I should try
logging the values for %{no-gzip}e and %{REDIRECT_no-gzip}e before I
bother with anything else?
Thanks again, Eric.
-Ben
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] gzipping via mod_deflate, the DeflateBufferSize,
the Content-Length header, and download progress in Web browsers
Posted by Eric Covener <co...@gmail.com>.
> Is there any chance that the SetEnvIfNoCase directive is not being
> satisfied due to the mod_rewrite rules that I'm using?
There's always a way for things to go wrong with mod_rewrite.
SetEnvIf would run both before and after your rewrite on both the
rewritten and un-rewritten URL, and environment variables would not
really live from the first pass to the second which is I think what
you're counting on. I suggest adding a rule to set no-gzip based on
the query string you'll redirect to.
Before you chase that, you can just log it the internal var with
%{no-gzip}e and %{REDIRECT_no-gzip}e
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] gzipping via mod_deflate, the DeflateBufferSize,
the Content-Length header, and download progress in Web browsers
Posted by Ben Johnson <be...@indietorrent.org>.
On 9/12/2012 1:16 PM, Ben Johnson wrote:
> Would it be better to disable GZIP compression for all URLs within the
> /download/ (for example) directory?
>
> Or perhaps for certain file-types? Because I tried that with the
> following, but it seems not to have any effect (I believe this example
> to be directly from the Apache documentation, with a few additional
> extensions added):
>
> <Location />
> SetOutputFilter DEFLATE
>
> # Don't compress images (or other files that are already compressed)
> SetEnvIfNoCase Request_URI \
> \.(?:gif|jpe?g|png|zip|7z|rar|sit?x|mp3|flac|ogg|pdf)$ no-gzip dont-vary
>
> # Make sure proxies don't deliver the wrong content
> Header append Vary User-Agent env=!dont-vary
> </Location>
>
> The URLs in question take the following format:
>
> https://localhost/public/download/My%20Installer.zip
>
> Also, I am setting the Content-Type header appropriately, e.g., to
> "application/zip", given the above URL.
>
> So, I'm not sure why that rule don't seem to be effective.
Is there any chance that the SetEnvIfNoCase directive is not being
satisfied due to the mod_rewrite rules that I'm using?
All requests are routed through a single file, /index.php, via the
following mod_rewrite directives:
# Rewrite URIs of the form 'index.php?q=x'
# (except for real files/directories):
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
So, a request for the URL
https://localhost/public/download/My%20Installer.zip will be rewritten
to https://localhost/public/index.php?q=/download/My%20Installer.zip .
Curiously, if I examine Apache's environment variables after the rewrite
has been performed, the "REQUEST_URI" value is
"/public/download/My%20Installer.zip".
Given the above, shouldn't the SetEnvIfNoCase directive return a match?
Thanks for any help!
-Ben
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] gzipping via mod_deflate, the DeflateBufferSize,
the Content-Length header, and download progress in Web browsers
Posted by Eric Covener <co...@gmail.com>.
> Whenever I enable GZIP compression on this page, via mod_deflate, Web
> browsers do not show the total file size to be downloaded, presumably
> because Apache is chunking the reply and the Content-Length header is
> very small, e.g., 20
Do you mean some of the chunk sizes? There should be no Content-Length header.
The browser cannot estimate the progress because neither client or
server knows how large the compressed file will be, because its
compressed on the fly.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org