cloudflare / pingora

A library for building fast, reliable and evolvable network services.
Apache License 2.0
20.21k stars 1.1k forks source link

ResponseCompression and cache cannot be used together #283

Open vicanso opened 2 weeks ago

vicanso commented 2 weeks ago

Describe the bug

Using ResponseCompression(zstd) or session.cache.enable alone works fine, but if the two functions are used together, the response data will be problematic for the first request.

< Accept-Ranges: bytes
< Content-Encoding: zstd
< X-GitHub-Request-Id: 2B0A:446E9:70615B4:71D6C78:666CF370
< X-Cache-Status: miss
< X-Cache-Lookup: 0ms
< Transfer-Encoding: chunked
< Connection: keep-alive
<
* Leftovers after chunking: 5 bytes
* Connection #0 to host localhost left intact

The second request is successful, but uncompressed:

< Accept-Ranges: bytes
< Transfer-Encoding: chunked
< X-GitHub-Request-Id: 2B69:15837D:891E3B:8C5A9C:666CF44B
< Age: 1
< X-Cache-Status: hit
< X-Cache-Lookup: 0ms
< Connection: keep-alive
<
{
  "id": 768613191,
....
...

Pingora info

Please include the following information about your environment:

Pingora version: 31d7b63ed7e3a1595903bca3680e130fe90e05a0 Rust version: cargo 1.78.0 (54d8815d0 2024-03-26) Operating system version: messense/rust-musl-cross:x86_64-musl

Steps to reproduce

Please provide step-by-step instructions to reproduce the issue. Include any relevant code snippets.

Expected results

What were you expecting to happen?

Observed results

What actually happened?

Additional context

What other information would you like to provide? e.g. screenshots, how you're working around the issue, or other clues you think could be helpful to identify the root cause.