I have some serious (or better say: strange) issues with the HTTP-header: Content-Encoding.
I want to gzip my content before sending it to the clients browser. For this I am checking if the clients browser accepts gzip and if so I am using ob_start("ob_gzhandler") and setting the content-encoding: $response->addHeader("Content-Encoding", "gzip");
-
I think my problem is the manual setting of the Content-Encoding header.
If I use$response->addHeader("Content-Encoding", "gzip");the content is only shown in Opera. -
If I use
$response->addHeader("Content-Encoding", "'gzip'");the content is shown correct in all browsers, but gzip compression checks say that it is not compressed and the W3C HTML Validation service cannot encode the page:
The error was: Don’t know how to decode Content-Encoding ”gzip”
- If I don’t use the line and online use
ob_start("ob_gzhandler")the page can only be shown in opera
My complete lines of code, which does correct output in browser is following:
$accEncoding = $request->getHeader("http_accept_encoding");
if($accEncoding !== NULL && substr_count($accEncoding, 'gzip')) {
ob_start("ob_gzhandler");
$response->addHeader("Content-Encoding", "'gzip'");
$response->addHeader("Vary", "Accept-Encoding");
} else {
ob_start();
}
Am I using the ob_gzhandler wrong or am I doing any other mistake here? I am very confused about the correct handling of gzip output.
ob_gzhandleralready verifies that the browser supports gzip compression:It also sets the Content-Encoding header accordingly.