如何在 Openshift 上禁用 gzip 压缩(针对特定请求)?更具体:对于 php 提供的文件下载 - 即fpassthrough
.
我尝试了几件事:
ini_set('zlib.output_compression', 'Off');
在 php 文件中apache_setenv('no-gzip', '1');
并apache_setenv('dont-vary', '1');
在 php 文件中SetEnv no-gzip dont-vary
在 .htaccess 文件中
仍然是一个简单的测试通过curl -v -H 'Accept-Encoding: gzip,deflate' http://downloadtest-***.rhcloud.com
给出:
> GET http://downloadtest-***.rhcloud.com/ HTTP/1.1
> User-Agent: curl/7.41.0
> Host: downloadtest-***.rhcloud.com
> Accept: */*
> Proxy-Connection: Keep-Alive
> Accept-Encoding: gzip,deflate
>
< HTTP/1.1 200 OK
< Date: Fri, 22 May 2015 12:47:41 GMT
< Server: Apache/2.2.15 (Red Hat)
< Content-Disposition: attachment; filename="myfile.tmp"
< Content-Lenght: 54
< Content-Type: application/octet-stream
< Vary: Accept-Encoding
< Content-Length: 77
< Proxy-Connection: Keep-Alive
< Connection: Keep-Alive
< Content-Encoding: gzip
背景:我需要禁用 gzip 压缩,因为它会损坏已压缩的文件 - 参见例如https://magento.stackexchange.com/questions/3528/downloadable-zip-files-are-corrupt或http://www.heath-whyte .info/david/computers/corrupted-zip-file-downloads-with-php。
完整的测试代码:
索引.php:
$file = __DIR__ . '/test.txt.gz'; //This file is acutally 54 bytes
ini_set('zlib.output_compression', 'Off');
apache_setenv('no-gzip', '1');
apache_setenv('dont-vary', '1');
header('Content-type: application/octet-stream');
header('Content-Disposition: attachment; filename="myfile.tmp"');
header('Content-Lenght: '.filesize($file));
if(!file_exists($file)) {
echo "file does not exist!\n";
exit(0);
}
$handle = fopen($file, 'rb');
fpassthru($handle);
fclose($handle);
exit(0);
.ht 访问:
RewriteEngine On
SetEnv no-gzip dont-vary