http2: fix subsequent end calls to not throw
Calling Http2ServerResponse.end multiple times should never cause the code to throw an error, subsequent calls should instead return false. Fix behaviour to match http1. Fixes: https://github.com/nodejs/node/issues/15385 PR-URL: https://github.com/nodejs/node/pull/15414 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
parent
bd85752871
commit
a4e923f5c1
@ -458,14 +458,13 @@ class Http2ServerResponse extends Stream {
|
||||
cb = encoding;
|
||||
encoding = 'utf8';
|
||||
}
|
||||
if (stream === undefined || stream.finished === true) {
|
||||
return false;
|
||||
}
|
||||
if (chunk !== null && chunk !== undefined) {
|
||||
this.write(chunk, encoding);
|
||||
}
|
||||
|
||||
if (stream === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof cb === 'function') {
|
||||
stream.once('finish', cb);
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
const { mustCall, mustNotCall, hasCrypto, skip } = require('../common');
|
||||
if (!hasCrypto)
|
||||
skip('missing crypto');
|
||||
const { strictEqual } = require('assert');
|
||||
const { doesNotThrow, strictEqual } = require('assert');
|
||||
const {
|
||||
createServer,
|
||||
connect,
|
||||
@ -19,6 +19,9 @@ const {
|
||||
// but may be invoked repeatedly without throwing errors.
|
||||
const server = createServer(mustCall((request, response) => {
|
||||
strictEqual(response.closed, false);
|
||||
response.on('finish', mustCall(() => process.nextTick(
|
||||
mustCall(() => doesNotThrow(() => response.end('test', mustNotCall())))
|
||||
)));
|
||||
response.end(mustCall(() => {
|
||||
server.close();
|
||||
}));
|
||||
|
Loading…
x
Reference in New Issue
Block a user