Skip to content

CachingResourceResolver + GzipResourceResolver caches different results depending on what is requested first [SPR-12892] #17491

Closed
@spring-projects-issues

Description

@spring-projects-issues
Collaborator

Michael de Hoog opened SPR-12892 and commented

I've configured a resource handler as below:

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry)
{
     GzipResourceResolver gzipResolver = new GzipResourceResolver();
     registry.addResourceHandler("/assets/**")
               .addResourceLocations("classpath:public/assets/")
               .setCachePeriod(0)
               .resourceChain(true)
               .addResolver(gzipResolver);
}

When requesting a resource from the server using curl, adding the "Accept-Encoding: gzip" header (using curl's --compressed flag), the GzipResourceResolver finds a .gz resource and returns it:

curl --compressed -v http://localhost:8080/assets/client.js

If I then request the same resource without the "Accept-Encoding: gzip" header, the gzipped version is still returned, as it is cached by the CachingResourceResolver:

curl -v http://localhost:8080/assets/client.js

If I restart the server and first call curl without the "Accept-Encoding: gzip" header, the non gzipped version is returned.

Then requesting the resource with the header still returns the non gzipped version.

To summarise, the server returns different results for the same request, depending on the request headers in the first request for the resource. This is because the CachingResourceResolver caches the resource only using the requestPath as the key, ignoring request headers.

Is this expected behaviour?


Affects: 4.1.6

Activity

spring-projects-issues

spring-projects-issues commented on May 4, 2015

@spring-projects-issues
CollaboratorAuthor

Brian Clozel commented

This has been resolved in master - will backport this for 4.1.7 (in the 4.1.x branch) soon.

Thanks for reporting this!

spring-projects-issues

spring-projects-issues commented on May 11, 2015

@spring-projects-issues
CollaboratorAuthor

Brian Clozel commented

This has been backported to 4.1.x.

added this to the 4.1.7 milestone on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: bugA general bug

Type

No type

Projects

No projects

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @bclozel@spring-projects-issues

      Issue actions

        CachingResourceResolver + GzipResourceResolver caches different results depending on what is requested first [SPR-12892] · Issue #17491 · spring-projects/spring-framework