Skip to content

Cannot remove headers from httpHeaders.keySet() in WebFlux #26361

@zeljko-mirovic

Description

@zeljko-mirovic

Affects: v5.3.2

I have ExchangeFilterFunction which should retain only allowed response headers:

private static final Collection<String> ALLOWED_RESPONSE_HEADERS = Arrays.asList(HttpHeaders.CONTENT_TYPE, HttpHeaders.CONTENT_DISPOSITION);

private ExchangeFilterFunction filterResponseHeaders() {
    return ExchangeFilterFunction.ofResponseProcessor(clientResponse -> Mono.just(ClientResponse.from(clientResponse)
            .headers(httpHeaders -> httpHeaders.keySet().removeIf(headerName -> !ALLOWED_RESPONSE_HEADERS.contains(headerName)))
            .body(clientResponse.bodyToFlux(DataBuffer.class))
            .build()));
}

This one is working correctly.

Because of ClientResponse.from() deprecation, the method is rewritten to:

private ExchangeFilterFunction filterResponseHeaders() {
    return ExchangeFilterFunction.ofResponseProcessor(clientResponse -> Mono.just(clientResponse.mutate()
            .headers(httpHeaders -> httpHeaders.keySet().removeIf(headerName -> !ALLOWED_RESPONSE_HEADERS.contains(headerName)))
            .build()));
}

That one is not working. Response headers are not affected.

Metadata

Metadata

Assignees

Labels

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

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions