Skip to content

Commit c1bc74c

Browse files
committed
ResponseEntityResponseExtractor tolerates unknown HTTP status codes
Issue: SPR-16371
1 parent f68fdd4 commit c1bc74c

File tree

3 files changed

+68
-83
lines changed

3 files changed

+68
-83
lines changed

spring-web/src/main/java/org/springframework/web/client/MessageBodyClientHttpResponseWrapper.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -57,9 +57,9 @@ public MessageBodyClientHttpResponseWrapper(ClientHttpResponse response) throws
5757
*/
5858
public boolean hasMessageBody() throws IOException {
5959
try {
60-
HttpStatus responseStatus = getStatusCode();
61-
if (responseStatus.is1xxInformational() || responseStatus == HttpStatus.NO_CONTENT ||
62-
responseStatus == HttpStatus.NOT_MODIFIED) {
60+
HttpStatus status = getStatusCode();
61+
if (status != null && status.is1xxInformational() || status == HttpStatus.NO_CONTENT ||
62+
status == HttpStatus.NOT_MODIFIED) {
6363
return false;
6464
}
6565
}

spring-web/src/main/java/org/springframework/web/client/RestTemplate.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import java.lang.reflect.Type;
2121
import java.net.URI;
2222
import java.util.ArrayList;
23-
import java.util.Collections;
2423
import java.util.LinkedList;
2524
import java.util.List;
2625
import java.util.Map;
@@ -931,10 +930,10 @@ public ResponseEntityResponseExtractor(Type responseType) {
931930
public ResponseEntity<T> extractData(ClientHttpResponse response) throws IOException {
932931
if (this.delegate != null) {
933932
T body = this.delegate.extractData(response);
934-
return new ResponseEntity<T>(body, response.getHeaders(), response.getStatusCode());
933+
return ResponseEntity.status(response.getRawStatusCode()).headers(response.getHeaders()).body(body);
935934
}
936935
else {
937-
return new ResponseEntity<T>(response.getHeaders(), response.getStatusCode());
936+
return ResponseEntity.status(response.getRawStatusCode()).headers(response.getHeaders()).build();
938937
}
939938
}
940939
}

0 commit comments

Comments
 (0)