New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept-Encoding not preserved when following redirects #9

Closed
mtdowling opened this Issue Mar 15, 2014 · 2 comments

Comments

Projects
None yet
2 participants
@mtdowling
Member

mtdowling commented Mar 15, 2014

See: guzzle/guzzle#541

Note: this is fixed in Guzzle 4

@mtdowling

This comment has been minimized.

Show comment
Hide comment
@mtdowling

mtdowling Oct 15, 2014

Member

Adding to known issues.

Member

mtdowling commented Oct 15, 2014

Adding to known issues.

@mtdowling mtdowling closed this Oct 15, 2014

@kminh

This comment has been minimized.

Show comment
Hide comment
@kminh

kminh Sep 28, 2015

Looks like Accept-Encoding is not preserved even for normal requests as well. I'm seeing this issue when using the Cache plugin with a Vary: Accept-Encoding response header. Example:

$client->get('a-url')->addHeader('Accept-Encoding', 'gzip')->send(); // a-url returns a 'Vary: Accept-Encoding' header
$client->get('a-url')->addHeader('Accept-Encoding', 'gzip')->send();

CURL output is:

* Connected to ....
> GET ... HTTP/1.1
Host: ....
Accept: */*
Accept-Encoding: gzip
User-Agent: Guzzle/3.9.2 curl/7.44.0 PHP/5.6.12
Via: 1.1 GuzzleCache/3.9.2

< HTTP/1.1 200 OK
< Date: Mon, 28 Sep 2015 15:20:07 GMT
< Server: Apache/2.4.16 (Unix) OpenSSL/1.0.2d mod_fastcgi/mod_fastcgi-SNAP-0910052141
< X-Powered-By: PHP/5.6.12
< Expires: Tue, 29 Sep 2015 15:20:07 GMT
< Vary: Accept-Encoding
< Cache-Control: max-age=86400
< Content-Encoding: gzip
< Last-Modified: Mon, 28 Sep 2015 15:20:05 GMT
< ETag: "..."
< Content-Length: 28326
< Content-Type: text/css; charset=utf-8

Although in both requests I set the same Accept-Encoding, the Cache plugin reported a cache MISS. Digging into the cache plugin's code I found out that both requests don't have Accept-Encoding header so there's nothing to compare between them.

The cause seems to be the same one mentioned in the original issue:

        // Add CURLOPT_ENCODING if Accept-Encoding header is provided
        if ($acceptEncodingHeader = $request->getHeader('Accept-Encoding')) {
            $curlOptions[CURLOPT_ENCODING] = (string) $acceptEncodingHeader;
            // Let cURL set the Accept-Encoding header, prevents duplicate values
            $request->removeHeader('Accept-Encoding');
        }

kminh commented Sep 28, 2015

Looks like Accept-Encoding is not preserved even for normal requests as well. I'm seeing this issue when using the Cache plugin with a Vary: Accept-Encoding response header. Example:

$client->get('a-url')->addHeader('Accept-Encoding', 'gzip')->send(); // a-url returns a 'Vary: Accept-Encoding' header
$client->get('a-url')->addHeader('Accept-Encoding', 'gzip')->send();

CURL output is:

* Connected to ....
> GET ... HTTP/1.1
Host: ....
Accept: */*
Accept-Encoding: gzip
User-Agent: Guzzle/3.9.2 curl/7.44.0 PHP/5.6.12
Via: 1.1 GuzzleCache/3.9.2

< HTTP/1.1 200 OK
< Date: Mon, 28 Sep 2015 15:20:07 GMT
< Server: Apache/2.4.16 (Unix) OpenSSL/1.0.2d mod_fastcgi/mod_fastcgi-SNAP-0910052141
< X-Powered-By: PHP/5.6.12
< Expires: Tue, 29 Sep 2015 15:20:07 GMT
< Vary: Accept-Encoding
< Cache-Control: max-age=86400
< Content-Encoding: gzip
< Last-Modified: Mon, 28 Sep 2015 15:20:05 GMT
< ETag: "..."
< Content-Length: 28326
< Content-Type: text/css; charset=utf-8

Although in both requests I set the same Accept-Encoding, the Cache plugin reported a cache MISS. Digging into the cache plugin's code I found out that both requests don't have Accept-Encoding header so there's nothing to compare between them.

The cause seems to be the same one mentioned in the original issue:

        // Add CURLOPT_ENCODING if Accept-Encoding header is provided
        if ($acceptEncodingHeader = $request->getHeader('Accept-Encoding')) {
            $curlOptions[CURLOPT_ENCODING] = (string) $acceptEncodingHeader;
            // Let cURL set the Accept-Encoding header, prevents duplicate values
            $request->removeHeader('Accept-Encoding');
        }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment