undici: request dont decompress response body
Bug Description
Why doesn’t request support response body decompression?
import { request } from "undici";
const resp = await request('https://jsonplaceholder.typicode.com/todos/1', {
headers: {
'accept-encoding': 'gzip'
}
});
const content = await resp.body.text();
console.log(`status:`, resp.statusCode);
console.log(`encoding:`, resp.headers['content-encoding']);
console.log(`body:`, content); // compressed
Logs & Screenshots
using fetch
using request
Environment
undici@5.24.0
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 3
- Comments: 18 (12 by maintainers)
Hello ! Maybe something automatic, like if the response contains gzip encoding header we should decompress it ?
Contributions are always welcomed
This issue has been pending for quite some time. When can we expect it to be resolved?
See
RetryHandlerto get a sense of how an interceptor looks like.I’m more into the possibility of creating a
DecompressHandlerthat infers thecontent-encodingheader and applies decompression, similar to what we are doing for retries on #2264, but -1 on adding it as part of the request options or within core at allI’m -1 in adding it to request, it would slow us down even if it’s not enabled.
I’m ok to add it under an option, if you really think it’s necessary.
That’s because there’s no hard need for
requestto decompress the body. By specfetchrequires to do so.This is not a bug in Undici but rather an expected outcome. Decompress is up to the responde handler and not to the client itself per se