如何在Openshift上禁用gzip压缩(针对特定请求)?更具体:对于由php提供的文件下载 - 即fpassthrough
。
我尝试了几件事:
ini_set('zlib.output_compression', 'Off');
apache_setenv('no-gzip', '1');
和apache_setenv('dont-vary', '1');
SetEnv no-gzip dont-vary
通过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。
完整的测试代码:
的index.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);
htaccess的:
RewriteEngine On
SetEnv no-gzip dont-vary
答案 0 :(得分:2)
压缩由OpenShift proxy执行,因此服务器的配置对其没有影响。我还没有找到任何禁用压缩的方法。例如,我尝试使用Cache-Control: no-transform
响应标头,并didn't work。