Skip to content

WEBrick::HTTPServlet::FileHandler: Fix if-range header returning 304 instead of 206/200 #173

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

metade
Copy link

@metade metade commented Aug 7, 2025

Range requests with if-range header were incorrectly returning 304 (Not Modified) status instead of the proper 206 (Partial Content) or 200 (OK) responses.

According to HTTP specification, if-range header should:

  • Return 206 (Partial Content) if the resource hasn't been modified
  • Return 200 (OK) with full content if the resource has been modified
  • Never return 304 (Not Modified)

The 304 behavior should only apply to if-modified-since and if-none-match headers, even for range requests.

Changes:

  • Move if-range handling out of not_modified? method into dedicated logic
  • Fix date precision issues in conditional header comparisons by normalizing to HTTP date format before comparison
  • Preserve existing 304 behavior for if-modified-since/if-none-match headers
  • Add comprehensive tests covering all if-range scenarios

Fixes range request behavior to comply with RFC 7233 specification.

(Note: Zed AI with Claude did most of this!)

…instead of 206/200

Range requests with if-range header were incorrectly returning 304 (Not Modified)
status instead of the proper 206 (Partial Content) or 200 (OK) responses.

According to HTTP specification, if-range header should:
- Return 206 (Partial Content) if the resource hasn't been modified
- Return 200 (OK) with full content if the resource has been modified
- Never return 304 (Not Modified)

The 304 behavior should only apply to if-modified-since and if-none-match
headers, even for range requests.

Changes:
- Move if-range handling out of not_modified? method into dedicated logic
- Fix date precision issues in conditional header comparisons by normalizing
  to HTTP date format before comparison
- Preserve existing 304 behavior for if-modified-since/if-none-match headers
- Add comprehensive tests covering all if-range scenarios

Fixes range request behavior to comply with RFC 7233 specification.
@metade
Copy link
Author

metade commented Aug 8, 2025

I have been feeling dirty about this as it is a lot of AI generated code!

I could try making a smaller change that tackles just the particular use case I'm after (hosting pmtiles on Jekyll).

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.

1 participant