-
-
Notifications
You must be signed in to change notification settings - Fork 69
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
Fix DecompressResponse Interceptor skipping decompression when Accept-Encoding is set manually #383
base: 5.x
Are you sure you want to change the base?
Conversation
…t-Encoding is set manually
This is actually by-design, e.g. if you build a reverse proxy, you don't want to decompress and compress again. If someone else sets the header, that code should also handle the decompression. |
Not sure if I get you. Can we make it configurable?
It actually doesn't handle decompression if I set Accept-Encoding manually, despite the registered Interceptor. Please check this example below. <?php
use Amp\Http\Client\HttpClientBuilder;
use Amp\Http\Client\Request;
require dirname(__DIR__, 1) . '/vendor/autoload.php';
$client = HttpClientBuilder::buildDefault();
$request = new Request('https://httpbin.org/gzip');
$request->setHeader('Accept-Encoding', 'gzip'); // <- This supresses DecompressResponse Interceptor
$response = $client->request($request);
var_dump($response->getBody()->buffer()); |
@@ -29,30 +29,20 @@ public function requestViaNetwork( | |||
Cancellation $cancellation, | |||
Stream $stream | |||
): Response { | |||
// If a header is manually set, we won't interfere |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See here, there's even a comment explaining that it will do nothing if the header is manually set.
Why do you need it to be configurable? Why do you set the header manually? I expect the compressed body to be var dumped, because as I said, if it's not the interceptor that sets the header, it does nothing by design. However, I get that the current naming of the interceptor is misleading, because it sounds like it only modifies the response and does so always, but it also modifies the request. |
I got you.
Yes, I think I misunderstood the purpose of this interceptor because its name.
I would like to control compression manually for each request, but the current interceptor is not suitable for this. What do you think about adding another interceptor with the logic from this PR? |
This PR fixes the DecompressResponse Interceptor.
Previously, if the Accept-Encoding header was manually set on a request, the interceptor would skip decompression, resulting in an encoded response body.
With this change, the DecompressResponse Interceptor determines whether to decompress the response based only on the Content-Encoding response header. It will decompress the body if this header contains a supported algorithm, regardless of the request headers.