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

ShallowETagHeaderFilter overwrites ETag #23775

Closed
cdalexndr opened this issue Oct 9, 2019 · 5 comments
Closed

ShallowETagHeaderFilter overwrites ETag #23775

cdalexndr opened this issue Oct 9, 2019 · 5 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: backported An issue that has been backported to maintenance branches type: bug A general bug
Milestone

Comments

@cdalexndr
Copy link

cdalexndr commented Oct 9, 2019

Affects: 5.2.0.RELEASE

Inside a @Controller I set the ETag and Cache-control header:

String etag = ...
if (webRequest.checkNotModified( etag ))
    return null;
response.setHeader( HttpHeaders.CACHE_CONTROL, CacheControl.maxAge( 30, TimeUnit.DAYS ).cachePublic().getHeaderValue() );

ShallowETagHeaderFilter overwrites ETag because isEligibleForEtag method returns true:

String cacheControl = response.getHeader(HttpHeaders.CACHE_CONTROL);
return (cacheControl == null || !cacheControl.contains(DIRECTIVE_NO_STORE));

ShallowEtagHeaderFilter should first check if an ETag is already set and skip it.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Oct 9, 2019
@rstoyanchev
Copy link
Contributor

I cannot find any calls to WebRequest#checkNotModified(String) in ShallowETagHeaderFilter. Can you please point to the source.

@rstoyanchev rstoyanchev added the status: waiting-for-feedback We need additional information before we can continue label Nov 1, 2019
@cdalexndr
Copy link
Author

@rstoyanchev sorry, wrong code snippet. Updated original post.

@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 Nov 1, 2019
@rstoyanchev
Copy link
Contributor

This was supposed to have been addressed as part of #22797 via 1a97a26 but I now see omissions:

  1. disableContentCachingIfNecessary should be invoked before the response is flushed.
  2. there is an inverted condition, if (!isRequestNotModified(webRequest)) that seems wrong.

I will prepare an update and maybe you can give it a try?

@rstoyanchev rstoyanchev self-assigned this Nov 4, 2019
@rstoyanchev rstoyanchev added in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug and removed status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged or decided on labels Nov 4, 2019
@rstoyanchev rstoyanchev added this to the 5.2.2 milestone Nov 4, 2019
@spring-projects-issues spring-projects-issues added status: backported An issue that has been backported to maintenance branches and removed for: backport-to-5.1.x labels Nov 6, 2019
@rstoyanchev
Copy link
Contributor

After taking a closer look, only the 2nd point from my previous comment is an issue and that matches the scenario here, (i.e. null return value handling for requestNotModified with an eTag).

@mickaeltr
Copy link

Hello,

As I explained in #22797 I am still having an issue with the ShallowEtagHeaderFilter overwriting ETag (and Content-Length), so I created a project with unit tests that demonstrate this: https://github.com/mickaeltr/Spring-ShallowEtagHeaderFilter-issue/blob/master/src/test/java/com/example/demo/DemoControllerTest.java

Thank you

rstoyanchev added a commit that referenced this issue Mar 4, 2020
These calls were added in error when trying to fix #22797 and #23775.
They are not needed in 304 scenarios. Those have no response content and
are skipped by ShallowETagHeaderFilter based on the status.

This leaves disableContentCaching invoked only in streaming scenarios,
which was the original intent and should be the only reason for that
method.

See gh-24635
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) status: backported An issue that has been backported to maintenance branches type: bug A general bug
Projects
None yet
Development

No branches or pull requests

4 participants