Support for non-standard HTTP status in reactive ClientHttpResponse
Issue: SPR-16748
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -31,10 +31,23 @@ import org.springframework.util.MultiValueMap;
|
||||
public interface ClientHttpResponse extends ReactiveHttpInputMessage {
|
||||
|
||||
/**
|
||||
* Return the HTTP status as an {@link HttpStatus} enum value.
|
||||
* Return the HTTP status code of the response.
|
||||
* @return the HTTP status as an HttpStatus enum value
|
||||
* @throws IllegalArgumentException in case of an unknown HTTP status code
|
||||
* @see HttpStatus#valueOf(int)
|
||||
*/
|
||||
HttpStatus getStatusCode();
|
||||
|
||||
/**
|
||||
* Return the HTTP status code (potentially non-standard and not
|
||||
* resolvable through the {@link HttpStatus} enum) as an integer.
|
||||
* @return the HTTP status as an integer
|
||||
* @since 5.0.6
|
||||
* @see #getStatusCode()
|
||||
* @see HttpStatus#resolve(int)
|
||||
*/
|
||||
int getRawStatusCode();
|
||||
|
||||
/**
|
||||
* Return a read-only map of response cookies received from the server.
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -55,6 +55,11 @@ public class ClientHttpResponseDecorator implements ClientHttpResponse {
|
||||
return this.delegate.getStatusCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRawStatusCode() {
|
||||
return this.delegate.getRawStatusCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpHeaders getHeaders() {
|
||||
return this.delegate.getHeaders();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -62,14 +62,18 @@ class ReactorClientHttpResponse implements ClientHttpResponse {
|
||||
@Override
|
||||
public HttpHeaders getHeaders() {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
this.response.responseHeaders().entries()
|
||||
.forEach(e -> headers.add(e.getKey(), e.getValue()));
|
||||
this.response.responseHeaders().entries().forEach(e -> headers.add(e.getKey(), e.getValue()));
|
||||
return headers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpStatus getStatusCode() {
|
||||
return HttpStatus.valueOf(this.response.status().code());
|
||||
return HttpStatus.valueOf(getRawStatusCode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRawStatusCode() {
|
||||
return this.response.status().code();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -91,7 +95,7 @@ class ReactorClientHttpResponse implements ClientHttpResponse {
|
||||
public String toString() {
|
||||
return "ReactorClientHttpResponse{" +
|
||||
"request=[" + this.response.method().name() + " " + this.response.uri() + "]," +
|
||||
"status=" + getStatusCode() + '}';
|
||||
"status=" + getRawStatusCode() + '}';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user