-
Notifications
You must be signed in to change notification settings - Fork 539
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
support slightly invalid gzip response #2123
Comments
I'm not sure how we could, this might be something to bring up inside Node.js iteself. |
We solved it with some zlibOptions options in node-fetch const buf = Buffer.from('H4sIAAAAAAAAE8tIzcnJVyjPL8pJAQA=', 'base64')
const readable = stream.Readable.from(buf)
// For Node v6+
// Be less strict when decoding compressed responses, since sometimes
// servers send slightly invalid responses that are still accepted
// by common browsers.
// Always using Z_SYNC_FLUSH is what cURL does.
const zlibOptions = {
flush: zlib.Z_SYNC_FLUSH,
finishFlush: zlib.Z_SYNC_FLUSH
}
// For gzip
if (codings === 'gzip' || codings === 'x-gzip') {
const ts = zlib.createGunzip(zlibOptions)
new Response(readable.pipe(ts)).text().then(console.log)
} |
just tested this and it seems to work okey without this it's described here in nodejs docs to about the use of
|
Then we should likely do the same. |
Relevant part of fetch: Line 2010 in f5f7c18
Want to send in a PR adding the options? That test could be added to the node-fetch suite. |
Now that NodeJS v16 is the current LTS and having web streams built in i was thinking about actually kind of delete everything in node-fetch (including all the test and so forth) and just bring in a dependency on Undici instead and simply just re-export everything. kind of like an alias for Undici. and piggy back on you to fix all our issues we have :P setting kind of have this in the pipe-line: import * as undici from 'undici'
const fetch = globalThis.fetch || undici.fetch
const FormData = globalThis.FormData || undici.FormData
const Headers = globalThis.Headers || undici.Headers
const Request = globalThis.Request || undici.Request
const Response = globalThis.Response || undici.Response
export default fetch
export {
fetch,
FormData,
Headers,
Request,
Response
}
export * from 'fetch-blob/from.js' just tough i would first share a few of our test cases that fails with undici before thinking of actually replacing it with undici. ref: node-fetch/node-fetch#1742 but sure i could maybe add a PR |
Here is one test we have in node-fetch, and i run it on undici fetch but it failed...
our test:
this works fine in browsers and some server ignore this CRC checksum and size at the end
The text was updated successfully, but these errors were encountered: