Repository navigation
Commit c8338a6
authored
fix(aws-lambda): always send the metadata prelude (#101)
On AWS Lambda, `sendStandardResponse` could send a response without its
metadata prelude, so the status, headers, and cookies were lost.
`HttpResponseStream.from()` only sets the prelude up, and the runtime
sends it just before the first `write()` call. `end(chunk)` skips that,
and empty bodies never call `write()`. The fix makes one empty write
right after `from()` so every response sends its prelude.
## Fixes
- JSON, URLSearchParams, `undefined`, empty-Blob, and empty-stream
responses now send their status, headers, and cookies. Before, they
reached the wire as just the body, or as zero bytes.
- Non-empty streamed responses are unaffected, apart from sending their
status and headers right away instead of waiting for the first chunk.
## Testing
- Checked against the stream code in `aws-lambda-ric` 4.0.2 (3.3.0 uses
the same prelude logic). The bytes were captured by a local HTTP server
standing in for the Lambda API. Every body type now carries the prelude
and delimiter exactly once. Not tested on a real Lambda deployment.
- The unit-test mock used to write the prelude itself, which hid the
bug. It now waits for the first `write()` like the runtime. Without the
fix, 3 tests fail: `buffered (empty)`, `buffered (json)`, and the new
`chunked (empty)`.1 parent a6c90ca commit c8338a6
3 files changed
Lines changed: 32 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | | - | |
17 | | - | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
18 | 23 | | |
19 | 24 | | |
20 | 25 | | |
| |||
159 | 164 | | |
160 | 165 | | |
161 | 166 | | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
162 | 184 | | |
163 | 185 | | |
164 | 186 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
| 49 | + | |
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
60 | 64 | | |
61 | 65 | | |
62 | 66 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
108 | | - | |
| 108 | + | |
| 109 | + | |
109 | 110 | | |
110 | 111 | | |
111 | 112 | | |
| |||
0 commit comments