Merge branch '5.3.x'
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,6 +17,8 @@
|
||||
package org.springframework.web.reactive.function.client;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
@@ -47,9 +49,24 @@ public class WebClientRequestException extends WebClientException {
|
||||
|
||||
this.method = method;
|
||||
this.uri = uri;
|
||||
this.headers = headers;
|
||||
this.headers = copy(headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Not all {@code HttpHeaders} implementations are serializable, so we
|
||||
* make a copy to ensure that {@code WebClientResponseException} is.
|
||||
*/
|
||||
private static HttpHeaders copy(HttpHeaders headers) {
|
||||
HttpHeaders result = new HttpHeaders();
|
||||
for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
|
||||
for (String value : entry.getValue()) {
|
||||
result.add(entry.getKey(), value);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the HTTP request method.
|
||||
*/
|
||||
|
||||
@@ -18,6 +18,8 @@ package org.springframework.web.reactive.function.client;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
@@ -53,11 +55,11 @@ public class WebClientResponseException extends WebClientException {
|
||||
private final Charset responseCharset;
|
||||
|
||||
@Nullable
|
||||
private final HttpRequest request;
|
||||
private transient final HttpRequest request;
|
||||
|
||||
@SuppressWarnings("MutableException")
|
||||
@Nullable
|
||||
private Function<ResolvableType, ?> bodyDecodeFunction;
|
||||
private transient Function<ResolvableType, ?> bodyDecodeFunction;
|
||||
|
||||
|
||||
/**
|
||||
@@ -133,12 +135,31 @@ public class WebClientResponseException extends WebClientException {
|
||||
|
||||
this.statusCode = statusCode;
|
||||
this.statusText = statusText;
|
||||
this.headers = (headers != null ? headers : HttpHeaders.EMPTY);
|
||||
this.headers = copy(headers);
|
||||
this.responseBody = (responseBody != null ? responseBody : new byte[0]);
|
||||
this.responseCharset = charset;
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Not all {@code HttpHeaders} implementations are serializable, so we
|
||||
* make a copy to ensure that {@code WebClientResponseException} is.
|
||||
*/
|
||||
private static HttpHeaders copy(@Nullable HttpHeaders headers) {
|
||||
if (headers == null) {
|
||||
return HttpHeaders.EMPTY;
|
||||
}
|
||||
else {
|
||||
HttpHeaders result = new HttpHeaders();
|
||||
for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
|
||||
for (String value : entry.getValue()) {
|
||||
result.add(entry.getKey(), value);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the HTTP status code value.
|
||||
|
||||
Reference in New Issue
Block a user