|
|
|
|
@ -21,9 +21,15 @@ import java.time.Duration;
@@ -21,9 +21,15 @@ import java.time.Duration;
|
|
|
|
|
import java.time.ZonedDateTime; |
|
|
|
|
import java.time.format.DateTimeFormatter; |
|
|
|
|
import java.time.format.DateTimeParseException; |
|
|
|
|
import java.util.Iterator; |
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
import org.apache.hc.client5.http.cookie.Cookie; |
|
|
|
|
import org.apache.hc.client5.http.cookie.CookieOrigin; |
|
|
|
|
import org.apache.hc.client5.http.cookie.CookieSpec; |
|
|
|
|
import org.apache.hc.client5.http.cookie.MalformedCookieException; |
|
|
|
|
import org.apache.hc.client5.http.protocol.HttpClientContext; |
|
|
|
|
import org.apache.hc.core5.http.Header; |
|
|
|
|
import org.apache.hc.core5.http.HttpResponse; |
|
|
|
|
import org.apache.hc.core5.http.Message; |
|
|
|
|
import org.reactivestreams.Publisher; |
|
|
|
|
@ -53,14 +59,27 @@ class HttpComponentsClientHttpResponse extends AbstractClientHttpResponse {
@@ -53,14 +59,27 @@ class HttpComponentsClientHttpResponse extends AbstractClientHttpResponse {
|
|
|
|
|
|
|
|
|
|
super(HttpStatusCode.valueOf(message.getHead().getCode()), |
|
|
|
|
HttpHeaders.readOnlyHttpHeaders(new HttpComponentsHeadersAdapter(message.getHead())), |
|
|
|
|
adaptCookies(context), |
|
|
|
|
adaptCookies(message.getHead(), context), |
|
|
|
|
Flux.from(message.getBody()).map(dataBufferFactory::wrap) |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static MultiValueMap<String, ResponseCookie> adaptCookies(HttpClientContext context) { |
|
|
|
|
private static MultiValueMap<String, ResponseCookie> adaptCookies( |
|
|
|
|
HttpResponse response, HttpClientContext context) { |
|
|
|
|
|
|
|
|
|
LinkedMultiValueMap<String, ResponseCookie> result = new LinkedMultiValueMap<>(); |
|
|
|
|
context.getCookieStore().getCookies().forEach(cookie -> |
|
|
|
|
|
|
|
|
|
CookieSpec cookieSpec = context.getCookieSpec(); |
|
|
|
|
CookieOrigin cookieOrigin = context.getCookieOrigin(); |
|
|
|
|
|
|
|
|
|
Iterator<Header> itr = response.headerIterator(HttpHeaders.SET_COOKIE); |
|
|
|
|
while (itr.hasNext()) { |
|
|
|
|
Header header = itr.next(); |
|
|
|
|
try { |
|
|
|
|
List<Cookie> cookies = cookieSpec.parse(header, cookieOrigin); |
|
|
|
|
for (Cookie cookie : cookies) { |
|
|
|
|
try { |
|
|
|
|
cookieSpec.validate(cookie, cookieOrigin); |
|
|
|
|
result.add(cookie.getName(), |
|
|
|
|
ResponseCookie.fromClientResponse(cookie.getName(), cookie.getValue()) |
|
|
|
|
.domain(cookie.getDomain()) |
|
|
|
|
@ -69,7 +88,18 @@ class HttpComponentsClientHttpResponse extends AbstractClientHttpResponse {
@@ -69,7 +88,18 @@ class HttpComponentsClientHttpResponse extends AbstractClientHttpResponse {
|
|
|
|
|
.secure(cookie.isSecure()) |
|
|
|
|
.httpOnly(cookie.containsAttribute("httponly")) |
|
|
|
|
.sameSite(cookie.getAttribute("samesite")) |
|
|
|
|
.build())); |
|
|
|
|
.build()); |
|
|
|
|
} |
|
|
|
|
catch (final MalformedCookieException ex) { |
|
|
|
|
// ignore invalid cookie
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
catch (final MalformedCookieException ex) { |
|
|
|
|
// ignore invalid cookie
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|