amphp / http-client

An advanced async HTTP client library for PHP, enabling efficient, non-blocking, and concurrent requests and responses.
https://amphp.org/http-client
MIT License
707 stars 66 forks source link

Keep content-encoding in a request attribute when using HTTP compression #237

Closed nicolas-grekas closed 4 years ago

nicolas-grekas commented 4 years ago

Removing this header means the consumer cannot assert if compression was used or not. And keeping it doesn't hurt in any way:

Note that this is how curl-based clients work and this is fine and more useful. This is needed to resolve https://github.com/symfony/symfony/pull/35115#pullrequestreview-337185999

kelunik commented 4 years ago

If another decoding interceptor is in the chain or the response is forwarded to a client in a reverse proxy, this would result in double decoding. How about setting a request attribute if the body has been decoded?

nicolas-grekas commented 4 years ago

How about setting a request attribute if the body has been decoded?

works for me, updated

nicolas-grekas commented 4 years ago

I order to monitor the raw download count, I'm not going to use DecompressResponse, so that this is not needed anymore on my side.

kelunik commented 4 years ago

You could use two interceptors counting the size before and after and still use DecompressResponse.

nicolas-grekas commented 4 years ago

You could use two interceptors counting the size before and after and still use DecompressResponse.

Sure. Yet, implementing the logic is very simple - simpler than writing two interceptors I'd say, so that's how I did :)