-
-
Notifications
You must be signed in to change notification settings - Fork 389
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
Bug: Compression is applied after request caching #1301
Comments
So, the issue here is that there is no |
I understand why it happens but I don't think it should happen. It seriously diminishes the value of Caching. If I want a compressed response in my cache I have to do this: def set(self, key: str, value: Any, expiration: int):
response: Response = pickle.loads(value)
data = gzip.compress(response.body, compresslevel=9)
response.body = data
response.headers["content-encoding"] = "gzip"
response.headers["transfer-encoding"] = "chunked"
re_pickled = pickle.dumps(response) |
Not disagreeing with you, I was just adding some context! |
I think the solution would be to caching into Middleware. This will be the most flexible option here. Thoughts on this? This is related also to the discussion in #1304 |
I agree. It could be set up similar to the
A bit but I don't think it's a blocker. All proposals currently in discussion there would have limited impact on this and would work just fine. |
It would still be easier though to add that one first if we chose to accept it 👀 |
So, I created a draft of this back in #1399, which I believe would solve this issue. |
Signed-off-by: Janek Nouvertné <[email protected]>
Signed-off-by: Janek Nouvertné <[email protected]>
Signed-off-by: Janek Nouvertné <[email protected]>
* fix: #1301 - Apply compression before caching Signed-off-by: Janek Nouvertné <[email protected]> * fix typing Signed-off-by: Janek Nouvertné <[email protected]> --------- Signed-off-by: Janek Nouvertné <[email protected]>
@chris-telemetry I finally got around to fix this one (= |
The CompressionMiddleware applies compression after CacheMiddleware caches the response and, on subsequent requests that hit the cache, applies compression every time.
I think in a perfect world the response would be cached after it is sent though I realize this comes with significant implementation issues.
Here's an easy way to reproduce:
The output for me, using a 1MB file for
test.txt
is:The text was updated successfully, but these errors were encountered: