1
votes

I wish to display the size of the file to the client when they download it.
But HTTP Header Content-Length not work.
My Environment is follow.

  • Apache 2.2
  • mod_deflate
  • Rails3.2

A download file is in the rails project public folder.

Response Header is this when I download it.

Accept-Ranges bytes
Access-Control-Allow-Head... origin, x-requested-with, content-type
Access-Control-Allow-Meth... PUT, GET, POST, DELETE, OPTIONS
Access-Control-Allow-Orig... http://*.com
Connection Keep-Alive
Content-Encoding gzip
Content-Type application/octet-stream
Date Fri, 14 Dec 2012 05:15:09 GMT
Etag "c1bcc-1c828800-4d0a3ac0f7389"
Keep-Alive timeout=5, max=100
Last-Modified Wed, 12 Dec 2012 08:34:51 GMT
Server Apache
Transfer-Encoding chunked
Vary Accept-Encoding

Is there any way to display the Content-Length?

1
If I disable the mod_deflate, Content-Length is displayed.Why?rainbow
Content-Length is displayed when it is small file. I think that buffer is not enough.rainbow
The problem was solved. I changed the setting of the apache, from using un-compressed file to using the pre-compressed file.rainbow
how did you do that? I'm facing the same issue.Ecarrion

1 Answers

1
votes

Although this is an old thread, it is a problem related to gzip compression. For others reading this question, here is my solution, based on this thread:

How to disable Apache gzip compression for some media files in .htaccess file?

You can add the following rule to your .htaccess

SetEnvIfNoCase Request_URI \.(?:gif|png|pdf|xxx)$ no-gzip dont-vary

if you want to disable compression for certain file types or

SetEnvIfNoCase Request_URI (url_to_not_compress) no-gzip dont-vary

if you have a script that forces a file to download.