Skip to content

Commit 265df15

Browse files
ryuhei shimaryuhei shima
authored andcommitted
http: reject addTrailers after finish
Fixes: #62809
1 parent d7e4108 commit 265df15

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

lib/_http_outgoing.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,10 @@ function connectionCorkNT(conn) {
977977
}
978978

979979
OutgoingMessage.prototype.addTrailers = function addTrailers(headers) {
980+
if (this.finished) {
981+
throw new ERR_HTTP_HEADERS_SENT('set trailing');
982+
}
983+
980984
this._trailer = '';
981985
const keys = ObjectKeys(headers);
982986
const isArray = ArrayIsArray(headers);

test/parallel/test-http-outgoing-proto.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,16 @@ assert.throws(() => {
129129
message: 'Invalid character in trailer content ["404"]'
130130
});
131131

132+
assert.throws(() => {
133+
const outgoingMessage = new OutgoingMessage();
134+
outgoingMessage.finished = true;
135+
outgoingMessage.addTrailers({ 'x-foo': 'bar' });
136+
}, {
137+
code: 'ERR_HTTP_HEADERS_SENT',
138+
name: 'Error',
139+
message: 'Cannot set trailing headers after they are sent to the client'
140+
});
141+
132142
{
133143
const outgoingMessage = new OutgoingMessage();
134144
assert.strictEqual(outgoingMessage.destroyed, false);

0 commit comments

Comments
 (0)