Content-type Header Not Handled Correctly for JSON and Form Data with Charset Information
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 55/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- javascript, node.js
- Lĩnh vực
- backend
Hướng nghiên cứu
Bắt đầu trong examples/middleware/bodyDecoder-middleware.js tại các dòng 47-53 và tái hiện request bằng cách sử dụng Content-type: application/json; charset=utf-8 hoặc dạng tương đương của header form-data. Xác minh rằng cả hai content type có tham số đều được decode và serialize chính xác, trong khi các content type thuần hiện có vẫn tiếp tục hoạt động.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Description
In the file bodyDecoder-middleware.js, lines 47-53, the server incorrectly handles Content-type: application/json; charset=utf-8 headers and similarly formatted headers for form data (application/x-www-form-urlencoded). The existing code uses strict string comparison, causing issues when the Content-type header contains additional properties like charset.
Existing Code
// bodyDecoder-middleware.js, lines 47-53
if (contentType === 'application/json') {
bodyData = JSON.stringify(req.body);
}
if (contentType === 'application/x-www-form-urlencoded') {
bodyData = queryString.stringify(req.body);
}
This code only works for requests that send a pure Content-type: application/json or Content-type: application/x-www-form-urlencoded without any additional properties like charset.
Expected behavior
The code should be able to handle Content-type headers with additional parameters.
Standard Practice According to MDN
According to MDN's documentation on Content-Type, the header can contain additional parameters (like charset), separated by a semicolon. Therefore, using startsWith would align better with this standard practice.
Solution
A possible solution is to change the string comparison to check if the Content-type starts with the desired value. Below is the proposed change:
if (contentType.startsWith('application/json')) {
bodyData = JSON.stringify(req.body);
}
if (contentType.startsWith('application/x-www-form-urlencoded')) {
bodyData = queryString.stringify(req.body);
}
Steps to Reproduce
- Send a POST request with a
Content-type: application/json; charset=utf-8header and JSON payload. - Observe that the existing code does not handle the body as expected.
Thank you for taking the time to look into this issue.
- Ngôn ngữ chính
- JavaScript
- Star
- 14.1k
- Fork
- 2k
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
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 http-party/node-http-proxy
-
util._extend() is depracatoryĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
http-party/node-http-proxy#1719 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 72/100
http-party/node-http-proxy#1721 · 1 bình luận ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 55/100
http-party/node-http-proxy#1715 · 1 bình luận · 5 reaction ·
-
Is this library is dead?Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 15/100
http-party/node-http-proxy#1711 · 2 bình luận ·
-
HTTP3 + QUIC support?Đang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
http-party/node-http-proxy#1710 · 5 reaction ·
Tất cả issue của http-party/node-http-proxy
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
microsoft/TypeScript#65370 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement good first issue priority: medium
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
TMHSDigital/Free-Game-Dev-Assets#272 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
metrics priority: medium
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 86/100
LearningCircuit/local-deep-research#8336 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
ace bug yaml
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 1 ngày
-
svelte: whitespace-only edit leaves an empty todo, edits not trimmed, filter not restored on reloadĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100