Skip to content

ServerWebExchange.mutate() does not delegate modified headers back to calling instance #34067

Closed as not planned
@Aafi01

Description

@Aafi01

Prior to spring-web-6.2.0 calling the mutate() method of ServerWebExchange and modifying the request headers would mutate the values in the calling instance of exchange object. This behavior matches the documentation of mutate() method. But this no longer works with version 6.2.0.

Dependency package: spring-web
Last working version: 6.1.13
Issue found in version: 6.2.0

MRE

Java version: 17
Dependencies: spring-boot-starter-webflux:3.4.0 (spring-web:6.2.0), spring-boot-starter-test:3.4.0

Following test fails:

@Test
void mutateShouldDelegateBackModifiedHeadersToThisInstance() {
    var mockServerHttpRequest = MockServerHttpRequest.get("/resource").build();
    var exchange = MockServerWebExchange.from(mockServerHttpRequest);

    String transactionId = UUID.randomUUID().toString();
    exchange.mutate().request(builder -> builder
            .header("Transaction-Id", transactionId));

    String transactionIdFromExchange = exchange.getRequest().getHeaders().getFirst("Transaction-Id");
    Assertions.assertEquals(transactionId, transactionIdFromExchange);
}

Using mutate().build() and using the returned exchange object still works as it did in version 6.1.13.

@Test
void mutateThenBuildShouldReturnModifiedHeaders() {
    var mockServerHttpRequest = MockServerHttpRequest.get("/resource").build();
    var exchange = MockServerWebExchange.from(mockServerHttpRequest);

    String transactionId = UUID.randomUUID().toString();
    var mutatedExchange = exchange.mutate().request(builder -> builder
            .header("Transaction-Id", transactionId)
    ).build();

    String transactionIdFromExchange = mutatedExchange.getRequest().getHeaders().getFirst("Transaction-Id");
    Assertions.assertEquals(transactionId, transactionIdFromExchange);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: webIssues in web modules (web, webmvc, webflux, websocket)status: invalidAn issue that we don't feel is valid

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions