HttpResponseStream doesn't work when `end`ing the stream without a `write`
還沒有人認領這個 Issue。
評估
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 新手友好度
- 38/100
- Issue 類型
- 缺陷
- 描述清晰度
- 基本清楚
- 活躍度
- 停滯
- 技術堆疊
- aws, node.js, typescript
研究方向
先閱讀 src/HttpResponseStream.js,特別是 onBeforeFirstWrite 的處理,然後追蹤 issue 中描述的 Node ClientRequest end 路徑。分別重現 responseStream.end("Not Found") 和 responseStream.end() 這兩種情況,並驗證自訂狀態碼和標頭在這兩種情況下都已套用。
由索引模型根據 Issue 內容生成。
描述
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:
export const handler = awslambda.streamifyResponse(
async (event, responseStream, context) => {
const metadata = {
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:
onBeforeFirstWrite is implemented by overriding http.ClientRequest stream's write:
// https://github.com/aws/aws-lambda-base-images/tree/nodejs18.x -> /var/runtime/index.mjs
req.write = function(chunk, encoding, callback) {
vvverbose("ResponseStream::write", chunk.length, "callback:", typeof callback);
if (typeof chunk !== "string" && !Buffer.isBuffer(chunk) && chunk?.constructor !== Uint8Array) {
chunk = JSON.stringify(chunk);
}
if (status === STATUS_READY && typeof this._onBeforeFirstWrite === "function") {
this._onBeforeFirstWrite((ch) => origWrite(ch));
}
const ret = origWrite(chunk, encoding, callback);
// [snip]
But turns out Node's ClientRequest doesn't call write when ending the stream with a final chunk of data, it calls an internal write_ instead:
I guess this could also be considered a Node bug, because their documentation for ClientRequest.end says:
If
datais specified, it is equivalent to callingrequest.write(data, encoding)followed byrequest.end(callback).
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().
- 主要語言
- TypeScript
- 星號
- 224
- 分支
- 60
- 平均合併
- 26 分鐘
- 30 天內合併 PR
- 2
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
aws/aws-lambda-nodejs-runtime-interface-client 的其他 Issue
-
難度 5/5 一週以上 新手友好度 20/100
aws/aws-lambda-nodejs-runtime-interface-client#198 · 3 則留言 · 6 個 reaction ·
-
難度 4/5 3-5 天 新手友好度 48/100
aws/aws-lambda-nodejs-runtime-interface-client#195 · 12 個 reaction ·
-
bug
aws/aws-lambda-nodejs-runtime-interface-client#170 · 15 則留言 · 6 個 reaction · 已指派 1 人 ·
-
難度 2/5 1-3 小時 新手友好度 38/100
aws/aws-lambda-nodejs-runtime-interface-client#159 · 2 個 reaction ·
-
難度 4/5 3-5 天 新手友好度 42/100
aws/aws-lambda-nodejs-runtime-interface-client#145 · 1 則留言 · 6 個 reaction ·
查看 aws/aws-lambda-nodejs-runtime-interface-client 的全部 Issue
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 84/100
Eynzof/Hermes-CN-Desktop#610 ·
-
bug clawsweeper:linked-pr-open clawsweeper:needs-live-repro clawsweeper:no-new-fix-pr impact:message-loss issue-rating: 🐚 platinum hermit P2 regression
難度 2/5 1-3 小時 新手友好度 78/100
-
enhancement
難度 2/5 1-3 小時 新手友好度 68/100
-
calcite-components needs triage refactor
難度 2/5 1-3 小時 新手友好度 75/100
Esri/calcite-design-system#15203 ·
-
難度 2/5 1-3 小時 新手友好度 90/100
danielmiessler/LifeOS#2218 ·