maslan
maslan

Reputation: 2178

How to serve static resources using webflux but with CACHE support

I have been trying to force spring cloud gateway to serve static html content from different directories under different paths, because it has multiple applications. Thanks to stackoverflow community it was simple in the beginning, I made some nice configurations etc and simply registered RouterFunctions in spring context, as many as I need:

@Bean
RouterFunction<ServerResponse> staticResourceRouter(){
    return RouterFunctions.resources("/an-application/**", new FileSystemResource("/something/blablastatic/"));
}

It works like a charm and I could replace some other static content serving systems that gateway was redirecting, they were obsolete.

The problem however appeared - everything I was able to find on the internet gives exactly the way as above, which does not use any client side resource caching (cache-control headers/ Last-Modified etc). I am not really proficient with webflux, and I am not sure how to configure this with manually (in the code, not spring boot properties) configured router functions, so that the server responds with 304 when the browser cache should be used. I would be grateful for some help.

Upvotes: 1

Views: 2157

Answers (1)

Brian Clozel
Brian Clozel

Reputation: 59086

The functional endpoint variant of Spring WebFlux is meant to be lightweight and give you more control over what happens. A vanilla WebFlux application would configure a resource handler with many options (cache control, transformation, etc), but I guess that in this case this might not be the preferred way with Spring Cloud Gateway.

I think this feature is not supported and this might be a good candidate for a new issue (if there's not one already). Note that this feature might be out of scope for Spring Cloud Gateway, since typically resource resolution/transformation requires often access to a local filesystem and local knowledge of the application serving that resource - which goes against proxying those requests for resources.

Upvotes: 2

Related Questions