Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Content-Length Header Conflict When Using Transfer-Encoding: chunked #20

Open
klkucaj opened this issue Dec 17, 2024 · 0 comments
Open
Assignees

Comments

@klkucaj
Copy link
Collaborator

klkucaj commented Dec 17, 2024

The HTTP specification (RFC 7230) states that when Transfer-Encoding: chunked is used, the Content-Length header must not be present in the same message. Including both headers causes ambiguity in how the body length is determined and violates the HTTP/1.1 standard.

Current Behavior:
When the Transfer-Encoding header includes chunked (alone or in combination with other encodings like gzip), the Content-Length header is still being sent in some cases. This results in undefined behavior and may cause protocol errors for HTTP clients or servers.

Expected Behavior:

  • If Transfer-Encoding: chunked is present, the Content-Length header should be omitted.
  • For other Transfer-Encoding values (e.g., gzip, compress, deflate) without chunked, the Content-Length can be included.

Examples of Valid Cases:
Transfer-Encoding: chunked (no Content-Length)
Transfer-Encoding: gzip + Content-Length: 100
Transfer-Encoding: deflate + Content-Length: 256

Examples of Invalid Cases:
Transfer-Encoding: chunked + Content-Length: 100
Transfer-Encoding: gzip, chunked + Content-Length: 150

Steps to Reproduce:

  1. Send an HTTP request or response with Transfer-Encoding: chunked and Content-Length set.
  2. Observe that both headers are sent.

Impact:
This issue violates HTTP/1.1 specifications and can lead to inconsistent handling of the response body by clients or servers, causing errors or unexpected behaviors.

Proposed Fix:

  • Add a validation step to ensure that if Transfer-Encoding contains chunked, the Content-Length header is not included.
  • Log or throw an error if both headers are detected.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Now 🔥
Development

No branches or pull requests

1 participant