Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/_http_outgoing.js
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,10 @@ function connectionCorkNT(conn) {
}

OutgoingMessage.prototype.addTrailers = function addTrailers(headers) {
if (this.finished) {
throw new ERR_HTTP_HEADERS_SENT('set trailing');
}

this._trailer = '';
const keys = ObjectKeys(headers);
const isArray = ArrayIsArray(headers);
Expand Down
10 changes: 10 additions & 0 deletions test/parallel/test-http-outgoing-proto.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@ assert.throws(() => {
message: 'Invalid character in trailer content ["404"]'
});

assert.throws(() => {
const outgoingMessage = new OutgoingMessage();
outgoingMessage.finished = true;
outgoingMessage.addTrailers({ 'x-foo': 'bar' });
}, {
code: 'ERR_HTTP_HEADERS_SENT',
name: 'Error',
message: 'Cannot set trailing headers after they are sent to the client'
});

{
const outgoingMessage = new OutgoingMessage();
assert.strictEqual(outgoingMessage.destroyed, false);
Expand Down
Loading