The following code for Cloud Gateway 4.1.5 works fine with Spring Boot 3.3.4:
exchange.getRequest().mutate().
uri(newUri).
headers(headers -> headers.addAll("key", "value")).
build();
but fails with the following stacktrace with Spring Boot 3.3.5:
java.lang.UnsupportedOperationException: null
at org.springframework.http.ReadOnlyHttpHeaders.addAll(ReadOnlyHttpHeaders.java:100) ~[spring-web-6.1.14.jar:6.1.14]
Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException:
Error has been observed at the following site(s):
*__checkpoint ⇢ org.springframework.cloud.gateway.filter.WeightCalculatorWebFilter [DefaultWebFilterChain]
*__checkpoint ⇢ org.springframework.security.web.server.WebFilterChainProxy [DefaultWebFilterChain]
*__checkpoint ⇢ HTTP GET "/queryParamToRequestHeader?Hello=World" [ExceptionHandlingWebHandler]
Original Stack Trace:
at org.springframework.http.ReadOnlyHttpHeaders.addAll(ReadOnlyHttpHeaders.java:100) ~[spring-web-6.1.14.jar:6.1.14]
at org.springframework.http.ReadOnlyHttpHeaders.addAll(ReadOnlyHttpHeaders.java:39) ~[spring-web-6.1.14.jar:6.1.14]
at org.springframework.http.HttpHeaders.addAll(HttpHeaders.java:1717) ~[spring-web-6.1.14.jar:6.1.14]
I have also tried Cloud Gateway 4.1.6-SNAPSHOT, which fails with same error and 4.2.0-M2, which instead requires Spring Boot 3.4.
The reason why it is failing seems to be quite clear (ReadOnlyHttpHeaders), still the javadoc for ServerHttpRequest.Builder.headers(Consumer<HttpHeaders>) and ServerHttpRequest.Builder.header(String, String[]) does not seem to be compatible with that.
Is there a way to change the code above to make it compatible with Spring Boot 3.3.5?
Thank you.
The following code for Cloud Gateway 4.1.5 works fine with Spring Boot 3.3.4:
but fails with the following stacktrace with Spring Boot 3.3.5:
I have also tried Cloud Gateway 4.1.6-SNAPSHOT, which fails with same error and 4.2.0-M2, which instead requires Spring Boot 3.4.
The reason why it is failing seems to be quite clear (
ReadOnlyHttpHeaders), still the javadoc forServerHttpRequest.Builder.headers(Consumer<HttpHeaders>)andServerHttpRequest.Builder.header(String, String[])does not seem to be compatible with that.Is there a way to change the code above to make it compatible with Spring Boot 3.3.5?
Thank you.