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

If-Unmodified-Since header check removes Last-Modified and Etag headers from response, even if condition passes #29362

Closed
molnarp opened this issue Oct 20, 2022 · 4 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Milestone

Comments

@molnarp
Copy link

molnarp commented Oct 20, 2022

Affects: 5.3.23

When handling the response, HttpEntityMethodProcessor calls isResourceNotModified() which removes the Last-Modified and Etag headers, set already in the response:
https://github.com/spring-projects/spring-framework/blob/5.3.x/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/HttpEntityMethodProcessor.java#L247

Subsequently, when WebServletRequest.checkNotModified() is invoked, it calls validateIfUnmodifiedSince(). If the header is present and populated with a valid value, this will return true, which will then go to a branch which invariably returns from the method. Further down, the two headers are readded, but those are never reached.

https://github.com/spring-projects/spring-framework/blob/5.3.x/spring-web/src/main/java/org/springframework/web/context/request/ServletWebRequest.java#L219

Therefore, even if the If-Unmodified-Since condition passes, those headers are removed from the response.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Oct 20, 2022
@molnarp
Copy link
Author

molnarp commented Oct 20, 2022

As far as I can tell, even though the code has changed in the main branch, the issue is still present:
https://github.com/spring-projects/spring-framework/blob/main/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/HttpEntityMethodProcessor.java#L266

Why does the isResourceNotModified() method remove those headers in the first place?

@bclozel
Copy link
Member

bclozel commented Oct 20, 2022

In these cases, a sample application demonstrating the problem would help a lot.
Could you share a small project (typically a small web app created with start.spring.io m) that we can git clone or download? Ideally, with a readme that lists a curl request, the expected result and what you got instead.

Pointing to various places in the codebase helps, but it's too early for that and we need consider the use case as a whole first.
Thanks!

@bclozel bclozel added the status: waiting-for-feedback We need additional information before we can continue label Oct 20, 2022
@molnarp
Copy link
Author

molnarp commented Oct 20, 2022

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Oct 20, 2022
@bclozel bclozel added in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged or decided on status: feedback-provided Feedback has been provided labels Oct 21, 2022
@bclozel bclozel self-assigned this Oct 21, 2022
@bclozel bclozel added this to the 5.3.24 milestone Oct 21, 2022
@bclozel
Copy link
Member

bclozel commented Oct 21, 2022

Thanks for the sample @molnarp , this is now fixed and will be released with our next maintenance version in November.

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: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants