Added ClientResponse.cookies()
Added cookies() method on ClientResponse, that exposes the response cookies. Issue: SPR-15236
This commit is contained in:
parent
2a512d7b9f
commit
da4af6157e
|
|
@ -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 {
|
|||
*/
|
||||
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
|
||||
|
|
|
|||
|
|
@ -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 {
|
|||
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() {
|
||||
|
|
|
|||
|
|
@ -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 {
|
|||
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…
Reference in New Issue