-
-
Notifications
You must be signed in to change notification settings - Fork 970
Open
Description
A response with enabled decompression is a prototype-child of a PassThrough
stream, but without the decompression, it's Node's IncomingMessage
.
This happens here in got
:
Line 655 in 3034c2f
response = decompressResponse(response); |
Why is it a problem
- We get different response objects based on the server's decision (compression/no compression). This is not very clear to anyone who needs to debug this.
- The
PassThrough
stream has some own properties hanging from it (e.g. theheaders
getter), but theIncomingMessage
response only inherits those from theIncomingMessage
prototype. This means that{ ...passThroughResponse }.headers
exists, but{ ...incomingMessageResponse }.headers
is undefined. See 1. - this only depends on the server's decision, so it gets really confusing.
Minimal reproduction scenario:
// compresedResponse is a PassThrough stream (because of the decompression)
const compressedResponse = await got('http://httpbin.org/gzip');
const { headers: gzipHeaders } = { ...compressedResponse };
// uncompressedResponse is an IncomingMessage (native Node.js response object)
const uncompressedResponse = await got('http://httpbin.org/html');
const { headers: htmlHeaders } = { ...uncompressedResponse };
console.log(`gzip response headers:`, gzipHeaders);
console.log(`html response headers:`, htmlHeaders);
results in
gzip response headers: {
date: 'Thu, 21 Nov 2024 13:14:39 GMT',
'content-type': 'application/json',
'content-length': '236',
connection: 'keep-alive',
server: 'gunicorn/19.9.0',
'content-encoding': 'gzip',
'access-control-allow-origin': '*',
'access-control-allow-credentials': 'true'
}
html response headers: undefined
Metadata
Metadata
Assignees
Labels
No labels