sindresorhus / got

🌐 Human-friendly and powerful HTTP request library for Node.js
MIT License
14.21k stars 935 forks source link

`got.stream` hangs when proxying invalid HTTP headers #1864

Open szmarczak opened 3 years ago

szmarczak commented 3 years ago
const net = require('net');
const http = require('http');
const {got} = require('got-cjs');

net.createServer(socket => {
    socket.end('HTTP/1.1 200 OK\r\ninvalid header: test\r\n\r\n');
}).listen(8888, async () => {
    const stream = got.stream('http://localhost:8888');
    stream.pipe(new http.ServerResponse({}));
    stream.on('error', () => {
        console.log('got error');
    });
    stream.on('end', () => {
        console.log('end!!');
    });
});

error & end never get emitted.

This line hangs in particular:

https://github.com/sindresorhus/got/blob/d4e34c7625c1c7000fd1b9af00e743669f83c83a/source/core/index.ts#L346

santoshyadavdev commented 3 years ago

I can give it a try.

santoshyadavdev commented 2 years ago

Hi @szmarczak I can see the package got now, I tried to use with got and it did went into error, when i tried to use got-cjs got exception related to import.

szmarczak commented 2 years ago

@santoshyadavdev Sorry for late response. I've already traced the issue: https://github.com/sindresorhus/get-stream/issues/46