Allow ServerHttpRequest content-type mutation
Prior to this commit, `ServerHttpRequest.mutate()` would not reflect changes made on the "Accept" and "Content-Type" HTTP headers. This was due to the fact that the instantiation of a new request based on the mutated values would not use the writable HTTP headers used during the mutation, but rather a read-only view of the headers backed by `ReadOnlyHttpHeaders`. `ReadOnlyHttpHeaders` caches those values for performance reasons, so getting those from the new request would not reflect the changes made during the mutation phase. This commit ensures that the new request uses the mutated headers. Fixes gh-26615
This commit is contained in:
@@ -38,6 +38,7 @@ import org.springframework.util.StringUtils;
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @author Sebastien Deleuze
|
||||
* @author Brian Clozel
|
||||
* @since 5.0
|
||||
*/
|
||||
class DefaultServerHttpRequestBuilder implements ServerHttpRequest.Builder {
|
||||
@@ -131,7 +132,7 @@ class DefaultServerHttpRequestBuilder implements ServerHttpRequest.Builder {
|
||||
@Override
|
||||
public ServerHttpRequest build() {
|
||||
return new MutatedServerHttpRequest(getUriToUse(), this.contextPath,
|
||||
this.httpMethodValue, this.sslInfo, this.remoteAddress, this.body, this.originalRequest);
|
||||
this.httpMethodValue, this.sslInfo, this.remoteAddress, this.headers, this.body, this.originalRequest);
|
||||
}
|
||||
|
||||
private URI getUriToUse() {
|
||||
@@ -190,9 +191,9 @@ class DefaultServerHttpRequestBuilder implements ServerHttpRequest.Builder {
|
||||
|
||||
public MutatedServerHttpRequest(URI uri, @Nullable String contextPath,
|
||||
String methodValue, @Nullable SslInfo sslInfo, @Nullable InetSocketAddress remoteAddress,
|
||||
Flux<DataBuffer> body, ServerHttpRequest originalRequest) {
|
||||
HttpHeaders headers, Flux<DataBuffer> body, ServerHttpRequest originalRequest) {
|
||||
|
||||
super(uri, contextPath, originalRequest.getHeaders());
|
||||
super(uri, contextPath, headers);
|
||||
this.methodValue = methodValue;
|
||||
this.remoteAddress = (remoteAddress != null ? remoteAddress : originalRequest.getRemoteAddress());
|
||||
this.sslInfo = (sslInfo != null ? sslInfo : originalRequest.getSslInfo());
|
||||
|
||||
Reference in New Issue
Block a user