Minor refactoring
Apply default Accept header for HttpUrlConnection only. See gh-23855
This commit is contained in:
@@ -91,6 +91,14 @@ final class SimpleBufferingClientHttpRequest extends AbstractBufferingClientHttp
|
||||
* @param headers the headers to add
|
||||
*/
|
||||
static void addHeaders(HttpURLConnection connection, HttpHeaders headers) {
|
||||
String method = connection.getRequestMethod();
|
||||
if (method.equals("PUT") || method.equals("DELETE")) {
|
||||
if (!StringUtils.hasText(headers.getFirst(HttpHeaders.ACCEPT))) {
|
||||
// Avoid "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2"
|
||||
// from HttpUrlConnection which prevents JSON error response details.
|
||||
headers.set(HttpHeaders.ACCEPT, "*/*");
|
||||
}
|
||||
}
|
||||
headers.forEach((headerName, headerValues) -> {
|
||||
if (HttpHeaders.COOKIE.equalsIgnoreCase(headerName)) { // RFC 6265
|
||||
String headerValue = StringUtils.collectionToDelimitedString(headerValues, "; ");
|
||||
|
||||
@@ -739,9 +739,6 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
|
||||
if (requestCallback != null) {
|
||||
requestCallback.doWithRequest(request);
|
||||
}
|
||||
if ((method == HttpMethod.DELETE || method == HttpMethod.PUT) && request.getHeaders().getAccept().isEmpty()) {
|
||||
request.getHeaders().add("Accept", "*/*");
|
||||
}
|
||||
response = request.execute();
|
||||
handleResponse(url, method, response);
|
||||
return (responseExtractor != null ? responseExtractor.extractData(response) : null);
|
||||
|
||||
Reference in New Issue
Block a user