HttpResponseStream doesn't work when `end`ing the stream without a `write`
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 38/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- aws, node.js, typescript
Hướng nghiên cứu
Bắt đầu bằng cách đọc src/HttpResponseStream.js, đặc biệt là phần xử lý onBeforeFirstWrite, sau đó lần theo đường dẫn kết thúc của Node ClientRequest được mô tả trong issue. Tái hiện cả trường hợp responseStream.end("Not Found") và responseStream.end(), đồng thời xác minh rằng mã trạng thái tùy chỉnh và các header được áp dụng trong cả hai trường hợp.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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().
- Ngôn ngữ chính
- TypeScript
- Star
- 224
- Fork
- 60
- Merge trung bình
- 26 phút
- Pull request đã merge (30 ngày)
- 2
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của aws/aws-lambda-nodejs-runtime-interface-client
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 20/100
aws/aws-lambda-nodejs-runtime-interface-client#198 · 3 bình luận · 6 reaction ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
aws/aws-lambda-nodejs-runtime-interface-client#195 · 12 reaction ·
-
bug
aws/aws-lambda-nodejs-runtime-interface-client#170 · 15 bình luận · 6 reaction · 1 người được giao ·
-
AWS Inspector findings for curl Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 38/100
aws/aws-lambda-nodejs-runtime-interface-client#159 · 2 reaction ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 42/100
aws/aws-lambda-nodejs-runtime-interface-client#145 · 1 bình luận · 6 reaction ·
Tất cả issue của aws/aws-lambda-nodejs-runtime-interface-client
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
Eynzof/Hermes-CN-Desktop#610 ·
-
[Bug]: Matrix progress drafts fail with "Matrix runtime not initialized" during tool activity Đang mởbug clawsweeper:linked-pr-open clawsweeper:needs-live-repro clawsweeper:no-new-fix-pr impact:message-loss issue-rating: 🐚 platinum hermit P2 regression
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
Client support matrix inclusion Đang mởenhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
-
calcite-components needs triage refactor
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Esri/calcite-design-system#15203 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 90/100
danielmiessler/LifeOS#2218 ·