You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using HttpResponseStream to set the status code and headers on a streaming response, I noticed that if I never call write on the stream, the custom status code and headers don't work.
Example repro:
exportconsthandler=awslambda.streamifyResponse(async(event,responseStream,context)=>{constmetadata={statusCode: 404,headers: {"Content-Type": "text/plain","X-Foo": "Bar"}};responseStream=awslambda.HttpResponseStream.from(responseStream,metadata);// This will cause a 502 with no custom response headers:responseStream.end("Not Found");// This will cause a 200 with no custom response headers:responseStream.end();});
I believe this is because HttpResponseStream relies on the onBeforeFirstWrite callback:
When using
HttpResponseStream
to set the status code and headers on a streaming response, I noticed that if I never callwrite
on the stream, the custom status code and headers don't work.Example repro:
I believe this is because
HttpResponseStream
relies on theonBeforeFirstWrite
callback:aws-lambda-nodejs-runtime-interface-client/src/HttpResponseStream.js
Lines 22 to 27 in 7374a4e
onBeforeFirstWrite
is implemented by overriding http.ClientRequest stream'swrite
:But turns out Node's
ClientRequest
doesn't callwrite
whenend
ing the stream with a finalchunk
of data, it calls an internalwrite_
instead:https://github.com/nodejs/node/blob/544cfc5ef151bca8d625fbccc581200a77b00bc0/lib/_http_outgoing.js#L1106
I guess this could also be considered a Node bug, because their documentation for
ClientRequest.end
says:But even if it did implement that contract correctly, there's still the case of ending the stream with no data, i.e.,
responseStream.end()
.The text was updated successfully, but these errors were encountered: