You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
HTTP2: Calling res.end after res.writeHead(204) cause an error #21740
changed the title [-]Http2: Calling `res.end` after `res.writeHead(204)` cause an error.[/-][+]HTTP2: Calling `res.end` after `res.writeHead(204)` cause an error.[/+]on Jul 10, 2018
changed the title [-]HTTP2: Calling `res.end` after `res.writeHead(204)` cause an error.[/-][+]HTTP2: Calling `res.end` after `res.writeHead(204)` cause an error[/+]on Jul 10, 2018
Hi!
I'm playing around with http2 module and server push and faced with a strange error.
Invoking of
res.end()method afterres.writeHeader(204)causes error:Code to reproduce:
After digging into the issue, I found out that if we set 204, 205 and 304 status codes the stream are closed automatically - see https://github.com/nodejs/node/blob/master/lib/internal/http2/core.js#L2266 and https://github.com/nodejs/node/blob/master/lib/internal/http2/core.js#L2281
Calling of
req.endmethod after that causes an error (see above).According to the documentation
req.end()MUST be called for each request: https://nodejs.org/api/http2.html#http2_response_end_data_encoding_callbackbut it is impossible due to closing the stream caused by calling
writeHeadermethod.I believe, in order to keep backward compatibility with
http/httpsmodules, theres.endmethod shouldn't throw an error in such case.