Skip to content

http2: respondWithFile() does not set headersSent to true #18862

Description

@trivikr
  • Version: v10.0.0-pre
  • Platform: N/A
  • Subsystem: http2

I came across this issue while writing unit tests for stream.respond() in PR #18861
The method respondWithFile() does not set state.flags, thus headersSent is still set to false:

respondWithFile(path,headers,options){
if(this.destroyed||this.closed)
thrownewerrors.Error('ERR_HTTP2_INVALID_STREAM');
if(this.headersSent)
thrownewerrors.Error('ERR_HTTP2_HEADERS_SENT');
assertIsObject(options,'options');
options=Object.assign({},options);
if(options.offset!==undefined&&typeofoptions.offset!=='number')
thrownewerrors.TypeError('ERR_INVALID_OPT_VALUE',
'offset',
options.offset);
if(options.length!==undefined&&typeofoptions.length!=='number')
thrownewerrors.TypeError('ERR_INVALID_OPT_VALUE',
'length',
options.length);
if(options.statCheck!==undefined&&
typeofoptions.statCheck!=='function'){
thrownewerrors.TypeError('ERR_INVALID_OPT_VALUE',
'statCheck',
options.statCheck);
}
letstreamOptions=0;
if(options.getTrailers!==undefined){
if(typeofoptions.getTrailers!=='function'){
thrownewerrors.TypeError('ERR_INVALID_OPT_VALUE',
'getTrailers',
options.getTrailers);
}
streamOptions|=STREAM_OPTION_GET_TRAILERS;
this[kState].getTrailers=options.getTrailers;
}
constsession=this[kSession];
debug(`Http2Stream ${this[kID]} [Http2Session `+
`${sessionName(session[kType])}]: initiating response`);
this[kUpdateTimer]();
headers=processHeaders(headers);
conststatusCode=headers[HTTP2_HEADER_STATUS]|=0;
// Payload/DATA frames are not permitted in these cases
if(statusCode===HTTP_STATUS_NO_CONTENT||
statusCode===HTTP_STATUS_RESET_CONTENT||
statusCode===HTTP_STATUS_NOT_MODIFIED){
thrownewerrors.Error('ERR_HTTP2_PAYLOAD_FORBIDDEN',statusCode);
}
fs.open(path,'r',
afterOpen.bind(this,session,options,headers,streamOptions));
}

This looks like a bug as both respond() and respondWithFD() set state.flags so that headersSent is set to true.

Metadata

Metadata

Assignees

No one assigned

    Labels

    http2Issues or PRs related to the http2 subsystem.invalidIssues and PRs that are invalid.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions