use of cn.taketoday.http.ResponseCookie in project today-infrastructure by TAKETODAY.
the class ServerHttpResponseTests method beforeCommitActionWithSetComplete.
@Test
void beforeCommitActionWithSetComplete() {
ResponseCookie cookie = ResponseCookie.from("ID", "123").build();
TestServerHttpResponse response = new TestServerHttpResponse();
response.beforeCommit(() -> {
response.getCookies().add(cookie.getName(), cookie);
return Mono.empty();
});
response.setComplete().block();
assertThat(response.statusCodeWritten).isTrue();
assertThat(response.headersWritten).isTrue();
assertThat(response.cookiesWritten).isTrue();
assertThat(response.body.isEmpty()).isTrue();
assertThat(response.getCookies().getFirst("ID")).isSameAs(cookie);
}
use of cn.taketoday.http.ResponseCookie in project today-infrastructure by TAKETODAY.
the class ServerHttpResponseTests method beforeCommitWithComplete.
@Test
void beforeCommitWithComplete() {
ResponseCookie cookie = ResponseCookie.from("ID", "123").build();
TestServerHttpResponse response = new TestServerHttpResponse();
response.beforeCommit(() -> Mono.fromRunnable(() -> response.getCookies().add(cookie.getName(), cookie)));
response.writeWith(Flux.just(wrap("a"), wrap("b"), wrap("c"))).block();
assertThat(response.statusCodeWritten).isTrue();
assertThat(response.headersWritten).isTrue();
assertThat(response.cookiesWritten).isTrue();
assertThat(response.getCookies().getFirst("ID")).isSameAs(cookie);
assertThat(response.body.size()).isEqualTo(3);
assertThat(new String(response.body.get(0).asByteBuffer().array(), StandardCharsets.UTF_8)).isEqualTo("a");
assertThat(new String(response.body.get(1).asByteBuffer().array(), StandardCharsets.UTF_8)).isEqualTo("b");
assertThat(new String(response.body.get(2).asByteBuffer().array(), StandardCharsets.UTF_8)).isEqualTo("c");
}
use of cn.taketoday.http.ResponseCookie in project today-infrastructure by TAKETODAY.
the class JettyClientHttpResponse method getCookies.
@Override
public MultiValueMap<String, ResponseCookie> getCookies() {
DefaultMultiValueMap<String, ResponseCookie> result = MultiValueMap.fromLinkedHashMap();
List<String> cookieHeader = getHeaders().get(HttpHeaders.SET_COOKIE);
if (cookieHeader != null) {
for (String header : cookieHeader) {
List<HttpCookie> httpCookies = HttpCookie.parse(header);
for (HttpCookie cookie : httpCookies) {
result.add(cookie.getName(), ResponseCookie.fromClientResponse(cookie.getName(), cookie.getValue()).domain(cookie.getDomain()).path(cookie.getPath()).maxAge(cookie.getMaxAge()).secure(cookie.getSecure()).httpOnly(cookie.isHttpOnly()).sameSite(parseSameSite(header)).build());
}
}
}
return MultiValueMap.unmodifiable(result);
}
use of cn.taketoday.http.ResponseCookie in project today-framework by TAKETODAY.
the class ServerHttpResponseTests method beforeCommitActionWithSetComplete.
@Test
void beforeCommitActionWithSetComplete() {
ResponseCookie cookie = ResponseCookie.from("ID", "123").build();
TestServerHttpResponse response = new TestServerHttpResponse();
response.beforeCommit(() -> {
response.getCookies().add(cookie.getName(), cookie);
return Mono.empty();
});
response.setComplete().block();
assertThat(response.statusCodeWritten).isTrue();
assertThat(response.headersWritten).isTrue();
assertThat(response.cookiesWritten).isTrue();
assertThat(response.body.isEmpty()).isTrue();
assertThat(response.getCookies().getFirst("ID")).isSameAs(cookie);
}
use of cn.taketoday.http.ResponseCookie in project today-framework by TAKETODAY.
the class ServerHttpResponseTests method beforeCommitWithComplete.
@Test
void beforeCommitWithComplete() {
ResponseCookie cookie = ResponseCookie.from("ID", "123").build();
TestServerHttpResponse response = new TestServerHttpResponse();
response.beforeCommit(() -> Mono.fromRunnable(() -> response.getCookies().add(cookie.getName(), cookie)));
response.writeWith(Flux.just(wrap("a"), wrap("b"), wrap("c"))).block();
assertThat(response.statusCodeWritten).isTrue();
assertThat(response.headersWritten).isTrue();
assertThat(response.cookiesWritten).isTrue();
assertThat(response.getCookies().getFirst("ID")).isSameAs(cookie);
assertThat(response.body.size()).isEqualTo(3);
assertThat(new String(response.body.get(0).asByteBuffer().array(), StandardCharsets.UTF_8)).isEqualTo("a");
assertThat(new String(response.body.get(1).asByteBuffer().array(), StandardCharsets.UTF_8)).isEqualTo("b");
assertThat(new String(response.body.get(2).asByteBuffer().array(), StandardCharsets.UTF_8)).isEqualTo("c");
}
Aggregations