mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
http2: make compat finished match http/1
finished should true directly after end(). PR-URL: https://github.com/nodejs/node/pull/24347 Refs: https://github.com/nodejs/node/issues/24743 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Ujjwal Sharma <ryzokuken@disroot.org> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
1 parent
bbb6cc733c
commit
9079bb42ea
2 files changed
+7
-8
No files matched your search
@@ -471,10 +471,8 @@ class Http2ServerResponse extends Stream {
|
||||
}
|
||||
|
||||
get finished() {
|
||||
const stream = this[kStream];
|
||||
return stream.destroyed ||
|
||||
stream._writableState.ended ||
|
||||
this[kState].closed;
|
||||
const state = this[kState];
|
||||
return state.ending;
|
||||
}
|
||||
|
||||
get socket() {
|
||||
@@ -700,12 +698,11 @@ class Http2ServerResponse extends Stream {
|
||||
if (chunk !== null && chunk !== undefined)
|
||||
this.write(chunk, encoding);
|
||||
|
||||
const isFinished = this.finished;
|
||||
state.headRequest = stream.headRequest;
|
||||
state.ending = true;
|
||||
|
||||
if (typeof cb === 'function') {
|
||||
if (isFinished)
|
||||
if (stream.writableEnded)
|
||||
this.once('finish', cb);
|
||||
else
|
||||
stream.once('finish', cb);
|
||||
@@ -714,7 +711,7 @@ class Http2ServerResponse extends Stream {
|
||||
if (!stream.headersSent)
|
||||
this.writeHead(this[kState].statusCode);
|
||||
|
||||
if (isFinished)
|
||||
if (this[kState].closed || stream.destroyed)
|
||||
onStreamCloseResponse.call(stream);
|
||||
else
|
||||
stream.end();
|
||||
|
||||
@@ -149,11 +149,13 @@ const {
|
||||
// Http2ServerResponse.end is necessary on HEAD requests in compat
|
||||
// for http1 compatibility
|
||||
const server = createServer(mustCall((request, response) => {
|
||||
strictEqual(response.finished, true);
|
||||
strictEqual(response.writableEnded, false);
|
||||
strictEqual(response.finished, false);
|
||||
response.writeHead(HTTP_STATUS_OK, { foo: 'bar' });
|
||||
strictEqual(response.finished, false);
|
||||
response.end('data', mustCall());
|
||||
strictEqual(response.writableEnded, true);
|
||||
strictEqual(response.finished, true);
|
||||
}));
|
||||
server.listen(0, mustCall(() => {
|
||||
const { port } = server.address();
|
||||
|
||||
Reference in new issue
Block a user