facebook / hhvm

A virtual machine for executing programs written in Hack.
https://hhvm.com
Other
18.15k stars 2.99k forks source link

Auto Content-Encoding: gzip and Transfer-Encoding: chunked only if necessary #4886

Open brusch opened 9 years ago

brusch commented 9 years ago

HHVM currently (Version 3.5.1) adds the following HTTP headers automatically:

Content-Encoding: gzip
Transfer-Encoding: chunked

But sometimes it's necessary / useful to decide in the acutual script if Content-Encoding/Transfer-Encoding is necessary or not and which values they should have.

It's also not possible to set the Content-Length header in a script because this gets overwritten by Transfer-Encoding: chunked.

Use-cases are:

So there should be the possibility to disable this feature on the fly (in the script) or it needs to have a better auto detection.

Following the comparison of Zend and HHVM

Zend:

HTTP/1.1 200 OK
Date: Mon, 23 Feb 2015 11:03:35 GMT
Server: Apache/2.2.22 (Debian)
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Connection: close
Content-Encoding: gzip
X-Powered-By: pimcore
Content-Length: 1503
Content-Type: application/json

HHVM

HTTP/1.1 200 OK
Date: Mon, 23 Feb 2015 11:03:09 GMT
Server: Apache/2.2.22 (Debian)
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Connection: close
Pragma: no-cache
Content-Encoding: gzip
Content-Encoding: gzip
X-Powered-By: pimcore
X-Powered-By: HHVM/3.5.1
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Transfer-Encoding: chunked
Content-Type: application/json

As you can see, ... HHVM adds another Content-Encoding header although there's already one set by the script and it removes the Content-Length header and adds Transfer-Encoding: chunked instead.

A workaround for now is to add the following configuration into the server.ini - but this disables this feature completely which isn't optimal in my opinion:

hhvm.server.gzip_compression_level = 0
brusch commented 9 years ago

In

HipHop VM 3.6.0-dev (rel)
Compiler: heads/master-0-g887af70ab3b502bf6761408ee5234dfcda103d43

the setting:

hhvm.server.gzip_compression_level = 0

doesn't seem to have an effect anymore, ... so there's no workaround anymore.