简体   繁体   中英

Disable gzip compression on Openshift (php cartridge)

How do I disable gzip compression on Openshift (for specific requests)? More specific: For file downloads served by php - ie fpassthrough .

I tried several things:

  • ini_set('zlib.output_compression', 'Off'); in the php file
  • apache_setenv('no-gzip', '1'); and apache_setenv('dont-vary', '1'); in the php file
  • SetEnv no-gzip dont-vary in the .htaccess file

Still a simple test via curl -v -H 'Accept-Encoding: gzip,deflate' http://downloadtest-***.rhcloud.com gives:

> 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

Background: I need to disable gzip compression as it corrupts already gzipped files - see eg https://magento.stackexchange.com/questions/3528/downloadable-zip-files-are-corrupt or http://www.heath-whyte.info/david/computers/corrupted-zip-file-downloads-with-php .


The complete test code:

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

The compression is performed by OpenShift proxy , so the configuration of your server has no effect on it. I haven't found any way to disable the compression. For example, I tried to use Cache-Control: no-transform response header, and it didn't work .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM