Browse Source

Added ClientResponse.cookies()

Added cookies() method on ClientResponse, that exposes the response
cookies.

Issue: SPR-15236
pull/1294/merge
Arjen Poutsma 8 years ago
parent
commit
da4af6157e
  1. 7
      spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ClientResponse.java
  2. 7
      spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultClientResponse.java
  3. 16
      spring-webflux/src/test/java/org/springframework/web/reactive/function/client/DefaultClientResponseTests.java

7
spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ClientResponse.java

@ -26,7 +26,9 @@ import reactor.core.publisher.Mono; @@ -26,7 +26,9 @@ import reactor.core.publisher.Mono;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseCookie;
import org.springframework.http.client.reactive.ClientHttpResponse;
import org.springframework.util.MultiValueMap;
import org.springframework.web.reactive.function.BodyExtractor;
/**
@ -51,6 +53,11 @@ public interface ClientResponse { @@ -51,6 +53,11 @@ public interface ClientResponse {
*/
Headers headers();
/**
* Return cookies of this response.
*/
MultiValueMap<String, ResponseCookie> cookies();
/**
* Extract the body with the given {@code BodyExtractor}. Unlike {@link #bodyToMono(Class)} and
* {@link #bodyToFlux(Class)}; this method does not check for a 4xx or 5xx status code before

7
spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultClientResponse.java

@ -32,8 +32,10 @@ import reactor.core.publisher.Mono; @@ -32,8 +32,10 @@ import reactor.core.publisher.Mono;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseCookie;
import org.springframework.http.client.reactive.ClientHttpResponse;
import org.springframework.http.codec.HttpMessageReader;
import org.springframework.util.MultiValueMap;
import org.springframework.web.reactive.function.BodyExtractor;
import org.springframework.web.reactive.function.BodyExtractors;
@ -68,6 +70,11 @@ class DefaultClientResponse implements ClientResponse { @@ -68,6 +70,11 @@ class DefaultClientResponse implements ClientResponse {
return this.headers;
}
@Override
public MultiValueMap<String, ResponseCookie> cookies() {
return this.response.getCookies();
}
@Override
public <T> T body(BodyExtractor<T, ? super ClientHttpResponse> extractor) {
return extractor.extract(this.response, new BodyExtractor.Context() {

16
spring-webflux/src/test/java/org/springframework/web/reactive/function/client/DefaultClientResponseTests.java

@ -39,11 +39,15 @@ import org.springframework.http.HttpHeaders; @@ -39,11 +39,15 @@ import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpRange;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseCookie;
import org.springframework.http.client.reactive.ClientHttpResponse;
import org.springframework.http.codec.DecoderHttpMessageReader;
import org.springframework.http.codec.HttpMessageReader;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.springframework.web.reactive.function.BodyExtractors.toMono;
@ -96,6 +100,18 @@ public class DefaultClientResponseTests { @@ -96,6 +100,18 @@ public class DefaultClientResponseTests {
assertEquals(httpHeaders, headers.asHttpHeaders());
}
@Test
public void cookies() throws Exception {
ResponseCookie cookie = ResponseCookie.from("foo", "bar").build();
MultiValueMap<String, ResponseCookie> cookies = new LinkedMultiValueMap<>();
cookies.add("foo", cookie);
when(mockResponse.getCookies()).thenReturn(cookies);
assertSame(cookies, defaultClientResponse.cookies());
}
@Test
public void body() throws Exception {
DefaultDataBufferFactory factory = new DefaultDataBufferFactory();

Loading…
Cancel
Save