Skip to content

Commit 9554610

Browse files
committed
fix: make sure metadata sent for bodyless responses
The streaming server was not returning the response metadata unless the body had some content to write to the stream. The fix is to always force a write with an empty string.
1 parent 9d3f692 commit 9554610

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lambda/serverless_streaming.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,16 @@ export const handler = awslambda.streamifyResponse(
6969

7070
responseStream = awslambda.HttpResponseStream.from(responseStream, metadata)
7171

72+
// Call write on the stream to trigger metadata to be sent
73+
// https://github.com/aws/aws-lambda-nodejs-runtime-interface-client/blob/2ce88619fd176a5823bc5f38c5484d1cbdf95717/src/HttpResponseStream.js#L22
74+
responseStream.write('')
75+
7276
if (rendered) {
7377
setResponse(responseStream, rendered)
7478
} else {
7579
responseStream.end()
7680
}
77-
}
81+
},
7882
)
7983

8084
// Copyright (c) 2020 [these people](https://github.com/sveltejs/kit/graphs/contributors) (MIT)
@@ -116,7 +120,7 @@ export async function setResponse(res, response) {
116120
if (response.body.locked) {
117121
res.end(
118122
'Fatal error: Response body is locked. ' +
119-
`This can happen when the response was already read (for example through 'response.json()' or 'response.text()').`
123+
`This can happen when the response was already read (for example through 'response.json()' or 'response.text()').`,
120124
)
121125
return
122126
}

0 commit comments

Comments
 (0)