Skip to content

Honor If-Range for resource range requests - #37218

Merged
bclozel merged 2 commits into
spring-projects:mainfrom
Gimini-3:fix/if-range-resource-responses
Oct 22, 2026
Merged

bclozel merged 2 commits into
spring-projects:mainfrom
Gimini-3:fix/if-range-resource-responses

Conversation

@Gimini-3

Copy link
Copy Markdown
Contributor

This change honors the If-Range request header when serving resource range requests.

A range is served only when If-Range contains a matching strong ETag or an HTTP-date that exactly matches the response's Last-Modified value. Otherwise, the Range header is ignored and the complete representation is returned.

The behavior is applied consistently to:

  • MVC static resource handling
  • MVC ResponseEntity<Resource>
  • WebMvc.fn resource responses
  • WebFlux resource responses

Regression tests cover matching and stale strong ETags, weak ETags, exact and mismatching HTTP dates, and a malformed Range combined with a stale If-Range.

Tests:

  • ./gradlew :spring-web:test :spring-webmvc:test :spring-webflux:test
  • Checkstyle for the affected main and test source sets
  • ./gradlew :spring-web:javadoc

Closes gh-27952

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Aug 31, 2026
@bclozel bclozel self-assigned this Aug 31, 2026
@bclozel bclozel added the in: web Issues in web modules (web, webmvc, webflux, websocket) label Aug 31, 2026
Gimini-3 and others added 2 commits October 22, 2026 10:09
Ignore Range when the If-Range validator does not match the
selected response representation. Apply the behavior consistently
to MVC and WebFlux resource responses.

Signed-off-by: Gimin Kim <138752849+Gimini-3@users.noreply.github.com>
Rename `HttpRange.parseRanges(HttpHeaders, HttpHeaders)` to
`resolveRanges` since it evaluates `If-Range` against the response in
addition to parsing the `Range` header, and cross-reference it from
`parseRanges(String)` and `HttpHeaders#getRange()`.

Also simplify the `If-Range` matching logic, document why weak entity
tags never match, and tidy up the tests.

See gh-37218
@bclozel
bclozel force-pushed the fix/if-range-resource-responses branch from 662b6fe to 05619fe Compare October 22, 2026 08:09
@bclozel
bclozel merged commit 05619fe into spring-projects:main Oct 22, 2026
1 of 2 checks passed
@bclozel bclozel added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Oct 22, 2026
@bclozel bclozel added this to the 7.1.0-RC2 milestone Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Range Requests do not take in to account the If-Range header set in the http request

3 participants