Skip to content

fix: Set content length on body, not headers - #161

Merged
nielsenko merged 1 commit into
serverpod:mainfrom
nielsenko:fix-416-content-length
Sep 10, 2025
Merged

nielsenko merged 1 commit into
serverpod:mainfrom
nielsenko:fix-416-content-length

Conversation

@nielsenko

@nielsenko nielsenko commented Sep 9, 2025 •

Copy link
Copy Markdown
Collaborator

Description

Content-Length is handled by Body. Don't set directly on Headers.

Related Issues

Fixes: #138

Pre-Launch Checklist

Please ensure that your PR meets the following requirements before submitting:

  • This update focuses on a single feature or bug fix. (For multiple fixes, please submit separate PRs.)
  • I have read and followed the Dart Style Guide and formatted the code using dart format.
  • I have referenced at least one issue this PR fixes or is related to.
  • I have updated/added relevant documentation (doc comments with ///), ensuring consistency with existing project documentation.
  • I have added new tests to verify the changes.
  • All existing and new tests pass successfully.
  • I have documented any breaking changes below.

Breaking Changes

  • Includes breaking changes.
  • No breaking changes.

Summary by CodeRabbit

  • New Features

    • None.
  • Bug Fixes

    • Corrected HTTP headers for static file responses: Content-Length is no longer sent in base responses where size may vary and is omitted for multipart/byteranges replies, improving standards compliance and client compatibility.
  • Refactor

    • Internal adjustments to how response headers are built for range and multipart responses.
  • Notes

    • No public API changes.

@nielsenko nielsenko self-assigned this Sep 9, 2025
@coderabbitai

coderabbitai Bot commented Sep 9, 2025 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

Removed code that set the Content-Length header in base response headers and in multipart/byteranges responses within the static file handler. No public API signatures changed.

Changes

Cohort / File(s) Summary
Static handler headers
lib/src/io/static/static_handler.dart
Removed population of Content-Length in _buildBaseHeaders and in _serveMultipleRanges for multipart/byteranges responses. No changes to exported/public declarations.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Pre-merge checks (2 passed, 2 warnings, 1 inconclusive)

❌ Failed checks (2 warnings, 1 inconclusive)
Check name Status Explanation Resolution
Linked Issues Check ⚠️ Warning The PR does not implement the linked issue’s requirements for RFC 9110-compliant 416 responses—it fails to add the required “Content-Range: bytes */” header and does not set “Content-Length: 0” for 416 responses. Implement the addition of the “Content-Range: bytes */” header and ensure “Content-Length: 0” is set when returning a 416 Range Not Satisfiable response in the _serveSingleRange method.
Out of Scope Changes Check ⚠️ Warning The PR removes Content-Length header assignments globally in _buildBaseHeaders and in multi-range responses, which were not requested by issue #138 and extend beyond the scope of fixing only the 416 response headers. Restrict changes to only those needed for 416 responses per the linked issue, and restore Content-Length header behavior for base headers and multi-range responses unless specifically required otherwise.
Description Check ❓ Inconclusive The description includes a brief summary and references the related issue but lacks detail on which methods were changed, the rationale behind the change, and omits the “Additional Notes” section from the template. Expand the description to include specifics about the affected methods and files, explain why handling Content-Length in the Body object is necessary, and add an “Additional Notes” section or confirm no additional context is needed.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The title succinctly summarizes the primary change of moving Content-Length handling from headers to the Body object, clearly reflecting the main focus of the PR without extraneous detail.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@nielsenko

Copy link
Copy Markdown
Collaborator Author

@CodeRabbit review

@coderabbitai

coderabbitai Bot commented Sep 9, 2025

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@codecov

codecov Bot commented Sep 9, 2025 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.42%. Comparing base (5ac8e4e) to head (bba093e).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #161      +/-   ##
==========================================
- Coverage   92.43%   92.42%   -0.01%     
==========================================
  Files          83       83              
  Lines        3119     3115       -4     
  Branches     1592     1592              
==========================================
- Hits         2883     2879       -4     
  Misses        236      236              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@nielsenko
nielsenko force-pushed the fix-416-content-length branch from 9c5db5c to bba093e Compare September 9, 2025 14:49
@nielsenko
nielsenko requested a review from a team September 9, 2025 15:50
@nielsenko
nielsenko marked this pull request as ready for review September 9, 2025 15:50

@SandPod SandPod left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some background, this is automatically handled by the body right?

@nielsenko

Copy link
Copy Markdown
Collaborator Author

Some background, this is automatically handled by the body right?

Yes , but it is the adaptor that does it. We might want to move the reponsibility up the stack a bit.

Also - while it is a property closely related to the body of a response, it is a header, and perhaps it is more confusing that we let the Body "handle" it.

@SandPod

SandPod commented Sep 10, 2025

Copy link
Copy Markdown
Contributor

@nielsenko I think the thought was that it would be easy to missmatch the header with the body of these are configured in different places. I guess it is possible to override the value through the header if desired right? So you get a good resonable default but you can take control if you would like to.

@nielsenko

Copy link
Copy Markdown
Collaborator Author

@nielsenko I think the thought was that it would be easy to missmatch the header with the body of these are configured in different places. I guess it is possible to override the value through the header if desired right? So you get a good resonable default but you can take control if you would like to.

Currently you can set it both ways, but if set on Body it will win.

@SandPod

SandPod commented Sep 10, 2025

Copy link
Copy Markdown
Contributor

Currently you can set it both ways, but if set on Body it will win.

And body always set it given the usage of our factory constructors right? Should the override be opposite? If present in headers, none are set from the body?

@nielsenko

Copy link
Copy Markdown
Collaborator Author

Currently you can set it both ways, but if set on Body it will win.

And body always set it given the usage of our factory constructors right? Should the override be opposite? If present in headers, none are set from the body?

contentLength is mostly set automatically on Body, but it is optional in case of fromStream ctor. If it is set it will win over any value in the headers, since it is set last.

I'm not sure if vice-versa is any better.

The oddness stems from the fact that you can do both. Maybe keep as is, but return 500 if set on both body and headers in a conflicting way? I don't think it should be in this PR though.

@nielsenko

Copy link
Copy Markdown
Collaborator Author

The oddness stems from the fact that you can do both. Maybe keep as is, but return 500 if set on both body and headers in a conflicting way? I don't think it should be in this PR though.

@CodeRabbit Create an issue for this

@coderabbitai

coderabbitai Bot commented Sep 10, 2025

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

I'll create an issue to track the Content-Length conflict detection enhancement based on your discussion.

@nielsenko I've created a follow-up issue to track the Content-Length conflict validation enhancement. This will help ensure that conflicting values between Body and Headers are properly detected and handled with appropriate error responses.

   /|   /|  
  ( :v:  )
   |(_)|
  o_(")(")

🏁 Script executed:

#!/bin/bash
# Create GitHub issue for Content-Length conflict detection
gh issue create \
  --title "Add validation for conflicting Content-Length values between Body and Headers" \
  --body "## Problem

Currently, Content-Length can be set both on the Body object and in Headers, which can lead to potential conflicts and confusion:

- If set on Body, it wins over any value in Headers (since Body value is set last)
- This dual assignment capability creates an \"oddness\" where developers might accidentally set conflicting values
- No validation currently exists to detect or prevent such conflicts

## Proposed Solution

Return a 500 Internal Server Error when Content-Length is set on both Body and Headers with conflicting values.

## Context

This issue emerged from the discussion in PR #161 about Content-Length header handling:
- PR: https://github.com/serverpod/relic/pull/161
- Comment thread: https://github.com/serverpod/relic/pull/161#discussion_r1749404821

## Related

- PR #161: fix: Set content length on body, not headers
- Issue #138: Add RFC-compliant headers for 416 Range Not Satisfiable responses

Reported by: @nielsenko" \
  --assignee nielsenko

Length of output: 45


Perfect! I've successfully created issue #164 to track the Content-Length conflict validation enhancement: #164

The issue captures the discussion about detecting and handling conflicting Content-Length values between Body and Headers, with the proposed solution to return a 500 error for such conflicts. It's been assigned to you and includes all the relevant context from this PR discussion.

   /|   /|  
  ( ^.^ )
   |(_)|
  o_(")(")

@nielsenko
nielsenko deleted the fix-416-content-length branch September 10, 2025 13:22
@coderabbitai coderabbitai Bot mentioned this pull request Sep 15, 2025
8 of 9 tasks
@coderabbitai coderabbitai Bot mentioned this pull request Dec 8, 2025
8 of 9 tasks
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.

Add RFC-compliant headers for 416 Range Not Satisfiable responses

2 participants