Skip to content

Missing CORS Headers for Static Resources in WebFlux #26495

Closed
@EusthEnoptEron

Description

@EusthEnoptEron

Affects: 5.3.3
Affected component: WebFlux

I created a configuration that roughly looks like this:

@EnableWebFlux
@Configuration
class WebfluxConfig : WebFluxConfigurer {
    override fun addResourceHandlers(registry: ResourceHandlerRegistry) {
        registry.addResourceHandler("/public/**")
            .addResourceLocations("classpath:/public/")
    }

    override fun addCorsMappings(registry: CorsRegistry) {
        registry.addMapping("/public/**")
            .allowedMethods("GET", "OPTIONS")
            .allowedOriginPatterns("*")
    }
}

Expectation:
A GET / OPTIONS request to http://localhost:8080/public/path/to/file should return with CORS headers.

Actual result:
CORS headers seem to be missing.

Possible cause:
In the bean declaration there seems to be no call to setCorsConfigurations() / configureAbstractHandlerMapping(), although there is in case of RequestMappingHandler and RouterFunctionMapping.
FWIW, in the MVC counterpart, this call seems to exist.

I tried adding that line using a breakpoint, after which CORS started working for me.


Sorry if I'm missing something obvious -- I'm just getting started with WebFlux. 😄
For the time being I guess I'll resort to a WebFilter.

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions