|
|
|
@ -16,6 +16,8 @@ |
|
|
|
|
|
|
|
|
|
|
|
package org.springframework.http.client.reactive; |
|
|
|
package org.springframework.http.client.reactive; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Collection; |
|
|
|
|
|
|
|
|
|
|
|
import io.netty.buffer.ByteBuf; |
|
|
|
import io.netty.buffer.ByteBuf; |
|
|
|
import io.reactivex.netty.protocol.http.client.HttpClientResponse; |
|
|
|
import io.reactivex.netty.protocol.http.client.HttpClientResponse; |
|
|
|
import reactor.core.converter.RxJava1ObservableConverter; |
|
|
|
import reactor.core.converter.RxJava1ObservableConverter; |
|
|
|
@ -25,7 +27,11 @@ import org.springframework.core.io.buffer.DataBuffer; |
|
|
|
import org.springframework.core.io.buffer.NettyDataBufferAllocator; |
|
|
|
import org.springframework.core.io.buffer.NettyDataBufferAllocator; |
|
|
|
import org.springframework.http.HttpHeaders; |
|
|
|
import org.springframework.http.HttpHeaders; |
|
|
|
import org.springframework.http.HttpStatus; |
|
|
|
import org.springframework.http.HttpStatus; |
|
|
|
|
|
|
|
import org.springframework.http.ResponseCookie; |
|
|
|
import org.springframework.util.Assert; |
|
|
|
import org.springframework.util.Assert; |
|
|
|
|
|
|
|
import org.springframework.util.CollectionUtils; |
|
|
|
|
|
|
|
import org.springframework.util.LinkedMultiValueMap; |
|
|
|
|
|
|
|
import org.springframework.util.MultiValueMap; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* {@link ClientHttpResponse} implementation for the RxNetty HTTP client |
|
|
|
* {@link ClientHttpResponse} implementation for the RxNetty HTTP client |
|
|
|
@ -38,8 +44,11 @@ public class RxNettyClientHttpResponse implements ClientHttpResponse { |
|
|
|
|
|
|
|
|
|
|
|
private final HttpHeaders headers; |
|
|
|
private final HttpHeaders headers; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final MultiValueMap<String, ResponseCookie> cookies; |
|
|
|
|
|
|
|
|
|
|
|
private final NettyDataBufferAllocator allocator; |
|
|
|
private final NettyDataBufferAllocator allocator; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public RxNettyClientHttpResponse(HttpClientResponse<ByteBuf> response, |
|
|
|
public RxNettyClientHttpResponse(HttpClientResponse<ByteBuf> response, |
|
|
|
NettyDataBufferAllocator allocator) { |
|
|
|
NettyDataBufferAllocator allocator) { |
|
|
|
Assert.notNull("'request', request must not be null"); |
|
|
|
Assert.notNull("'request', request must not be null"); |
|
|
|
@ -48,8 +57,26 @@ public class RxNettyClientHttpResponse implements ClientHttpResponse { |
|
|
|
this.response = response; |
|
|
|
this.response = response; |
|
|
|
this.headers = new HttpHeaders(); |
|
|
|
this.headers = new HttpHeaders(); |
|
|
|
this.response.headerIterator().forEachRemaining(e -> this.headers.set(e.getKey(), e.getValue())); |
|
|
|
this.response.headerIterator().forEachRemaining(e -> this.headers.set(e.getKey(), e.getValue())); |
|
|
|
|
|
|
|
this.cookies = initCookies(response); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static MultiValueMap<String, ResponseCookie> initCookies(HttpClientResponse<ByteBuf> response) { |
|
|
|
|
|
|
|
MultiValueMap<String, ResponseCookie> result = new LinkedMultiValueMap<>(); |
|
|
|
|
|
|
|
response.getCookies().values().stream().flatMap(Collection::stream) |
|
|
|
|
|
|
|
.forEach(cookie -> { |
|
|
|
|
|
|
|
ResponseCookie responseCookie = ResponseCookie.from(cookie.name(), cookie.value()) |
|
|
|
|
|
|
|
.domain(cookie.domain()) |
|
|
|
|
|
|
|
.path(cookie.path()) |
|
|
|
|
|
|
|
.maxAge(cookie.maxAge()) |
|
|
|
|
|
|
|
.secure(cookie.isSecure()) |
|
|
|
|
|
|
|
.httpOnly(cookie.isHttpOnly()) |
|
|
|
|
|
|
|
.build(); |
|
|
|
|
|
|
|
result.add(cookie.name(), responseCookie); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
return CollectionUtils.unmodifiableMultiValueMap(result); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public HttpStatus getStatusCode() { |
|
|
|
public HttpStatus getStatusCode() { |
|
|
|
return HttpStatus.valueOf(this.response.getStatus().code()); |
|
|
|
return HttpStatus.valueOf(this.response.getStatus().code()); |
|
|
|
@ -64,4 +91,10 @@ public class RxNettyClientHttpResponse implements ClientHttpResponse { |
|
|
|
public HttpHeaders getHeaders() { |
|
|
|
public HttpHeaders getHeaders() { |
|
|
|
return this.headers; |
|
|
|
return this.headers; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public MultiValueMap<String, ResponseCookie> getCookies() { |
|
|
|
|
|
|
|
return this.cookies; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|