1

如何在 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-corrupthttp://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
4

1 回答 1

2

压缩是由OpenShift 代理执行的,因此您的服务器配置对其没有影响。我还没有找到任何方法来禁用压缩。例如,我尝试使用Cache-Control: no-transform响应头,但它不起作用

于 2015-06-26T18:43:30.497 回答