File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -977,6 +977,10 @@ function connectionCorkNT(conn) {
977977}
978978
979979OutgoingMessage . 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 ) ;
Original file line number Diff line number Diff 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 ) ;
You can’t perform that action at this time.
0 commit comments