如何使用 webflux 提供静态资源但支持缓存
How to serve static resources using webflux but with CACHE support
我一直在尝试强制 spring 云网关在不同路径下提供来自不同目录的静态 html 内容,因为它有多个应用程序。感谢 Whosebug 社区,一开始它很简单,我做了一些不错的配置等,并简单地在 spring 上下文中注册了 RouterFunctions,我需要多少就注册多少:
@Bean
RouterFunction<ServerResponse> staticResourceRouter(){
return RouterFunctions.resources("/an-application/**", new FileSystemResource("/something/blablastatic/"));
}
它就像一个魅力,我可以替换网关重定向的其他一些静态内容服务系统,它们已经过时了。
然而问题出现了——我在互联网上找到的一切都给出了与上面完全相同的方式,它不使用任何客户端资源缓存(cache-control headers/ Last-Modified 等)。我不是很精通 webflux,我不确定如何使用手动配置(在代码中,而不是 spring 启动属性)配置路由器功能,以便服务器在浏览器缓存应该是时以 304 响应用过的。我将不胜感激。
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),但我想在这种情况下,这可能不是 Spring 云网关的首选方式。
我认为此功能不受支持,这可能是 good candidate for a new issue(如果还没有的话)。请注意,此功能可能超出 Spring Cloud Gateway 的范围,因为通常资源 resolution/transformation 需要经常访问本地文件系统和服务于该资源的应用程序的本地知识 - 这与代理这些请求不符资源。
我一直在尝试强制 spring 云网关在不同路径下提供来自不同目录的静态 html 内容,因为它有多个应用程序。感谢 Whosebug 社区,一开始它很简单,我做了一些不错的配置等,并简单地在 spring 上下文中注册了 RouterFunctions,我需要多少就注册多少:
@Bean
RouterFunction<ServerResponse> staticResourceRouter(){
return RouterFunctions.resources("/an-application/**", new FileSystemResource("/something/blablastatic/"));
}
它就像一个魅力,我可以替换网关重定向的其他一些静态内容服务系统,它们已经过时了。
然而问题出现了——我在互联网上找到的一切都给出了与上面完全相同的方式,它不使用任何客户端资源缓存(cache-control headers/ Last-Modified 等)。我不是很精通 webflux,我不确定如何使用手动配置(在代码中,而不是 spring 启动属性)配置路由器功能,以便服务器在浏览器缓存应该是时以 304 响应用过的。我将不胜感激。
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),但我想在这种情况下,这可能不是 Spring 云网关的首选方式。
我认为此功能不受支持,这可能是 good candidate for a new issue(如果还没有的话)。请注意,此功能可能超出 Spring Cloud Gateway 的范围,因为通常资源 resolution/transformation 需要经常访问本地文件系统和服务于该资源的应用程序的本地知识 - 这与代理这些请求不符资源。