Skip to content

Fix RFC 7230 §3.3.3 violation: Transfer-Encoding takes precedence over Content-Length#5

Merged
dragosv merged 3 commits intounixsocketfrom
copilot/sub-pr-1-another-one
Mar 5, 2026
Merged

Fix RFC 7230 §3.3.3 violation: Transfer-Encoding takes precedence over Content-Length#5
dragosv merged 3 commits intounixsocketfrom
copilot/sub-pr-1-another-one

Conversation

Copy link
Contributor

Copilot AI commented Mar 5, 2026

When both Transfer-Encoding: chunked and Content-Length headers are present, readResponseBody was checking content_length first — violating RFC 7230 §3.3.3, which mandates that Transfer-Encoding takes precedence and Content-Length must be ignored.

Description

Reorder the checks in readResponseBody so meta.chunked is evaluated before meta.content_length:

// Before (incorrect precedence)
fn readResponseBody(...) ![]const u8 {
    if (meta.content_length) |cl| { ... }  // checked first — wrong
    if (meta.chunked) { ... }

// After (RFC-compliant)
fn readResponseBody(...) ![]const u8 {
    if (meta.chunked) { ... }              // Transfer-Encoding wins per RFC 7230 §3.3.3
    if (meta.content_length) |cl| { ... }

Added a /// doc comment citing the RFC so the ordering intent is self-documenting.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring
  • Performance improvement
  • Test addition/modification
  • CI/CD changes

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Testing

  • Unit tests

Additional Notes

This is a correctness fix for an edge case (server sending both headers). Docker's own API is well-behaved, but the fix ensures correct behaviour against any RFC-conformant or buggy intermediary.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…7230 §3.3.3

Co-authored-by: dragosv <422243+dragosv@users.noreply.github.com>
Copilot AI changed the title [WIP] Address feedback on UNIX sockets implementation Fix RFC 7230 §3.3.3 violation: Transfer-Encoding takes precedence over Content-Length Mar 5, 2026
@dragosv dragosv marked this pull request as ready for review March 5, 2026 06:40
@dragosv dragosv self-requested a review as a code owner March 5, 2026 06:40
@dragosv dragosv merged commit fb72191 into unixsocket Mar 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants