Skip to content
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

Fetch never resolves on empty response with deflate #1442

Closed
szmarczak opened this issue Jan 6, 2022 · 4 comments · Fixed by #965
Closed

Fetch never resolves on empty response with deflate #1442

szmarczak opened this issue Jan 6, 2022 · 4 comments · Fixed by #965

Comments

@szmarczak
Copy link

const fetch = require('node-fetch');
const http = require('http');

const server = http.createServer((request, response) => {
        response.setHeader('content-encoding', 'deflate'); // change this to gzip and it works
        response.end();
});

server.listen(8080);

(async () => {
        const response = await fetch('http://localhost:8080');
        const text = await response.text();

        console.log('Result:', text);

        server.close();
})();

Looks like you're missing

+				let hasData = false;
				raw.once('data', chunk => {
+					hasData = true;
					// See http://stackoverflow.com/questions/37519828
					body = (chunk[0] & 0x0F) === 0x08 ? pump(body, zlib.createInflate(), reject) : pump(body, zlib.createInflateRaw(), reject);

					response = new Response(body, responseOptions);
					resolve(response);
				});
+
+				raw.once('end', () => {
+					if (!hasData) {
+						response = new Response(body, responseOptions);
+						resolve(response);
+					}
+				});

before

return;

@szmarczak szmarczak added the bug label Jan 6, 2022
@JefferyHus
Copy link
Member

Good catch there, @jimmywarting if you confirm, I would love to take care of fixing this

@bitinn
Copy link
Collaborator

bitinn commented Jan 10, 2022

@JefferyHus sounds fair, you can go ahead with the PR :)

@jimmywarting
Copy link
Collaborator

closing as dupl of #965

@github-actions
Copy link

🎉 This issue has been resolved in version 3.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants