use of org.springframework.http.ResponseCookie in project spring-framework by spring-projects.
the class CookieWebSessionIdResolver method setSessionId.
@Override
public void setSessionId(ServerWebExchange exchange, String id) {
Assert.notNull(id, "'id' is required");
ResponseCookie cookie = initSessionCookie(exchange, id, getCookieMaxAge());
exchange.getResponse().getCookies().set(this.cookieName, cookie);
}
use of org.springframework.http.ResponseCookie in project spring-framework by spring-projects.
the class DefaultClientResponseTests method cookies.
@Test
public void cookies() {
ResponseCookie cookie = ResponseCookie.from("foo", "bar").build();
MultiValueMap<String, ResponseCookie> cookies = new LinkedMultiValueMap<>();
cookies.add("foo", cookie);
given(mockResponse.getCookies()).willReturn(cookies);
assertThat(defaultClientResponse.cookies()).isSameAs(cookies);
}
use of org.springframework.http.ResponseCookie in project spring-framework by spring-projects.
the class DefaultServerResponseBuilderTests method build.
@Test
public void build() {
ResponseCookie cookie = ResponseCookie.from("name", "value").build();
Mono<ServerResponse> result = ServerResponse.status(HttpStatus.CREATED).header("MyKey", "MyValue").cookie(cookie).build();
MockServerHttpRequest request = MockServerHttpRequest.get("https://example.com").build();
MockServerWebExchange exchange = MockServerWebExchange.from(request);
result.flatMap(res -> res.writeTo(exchange, EMPTY_CONTEXT)).block();
MockServerHttpResponse response = exchange.getResponse();
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.CREATED);
assertThat(response.getHeaders().getFirst("MyKey")).isEqualTo("MyValue");
assertThat(response.getCookies().getFirst("name").getValue()).isEqualTo("value");
StepVerifier.create(response.getBody()).expectComplete().verify();
}
use of org.springframework.http.ResponseCookie in project spring-framework by spring-projects.
the class DefaultServerResponseBuilderTests method from.
@Test
public void from() {
ResponseCookie cookie = ResponseCookie.from("foo", "bar").build();
ServerResponse other = ServerResponse.ok().header("foo", "bar").cookie(cookie).hint("foo", "bar").build().block();
Mono<ServerResponse> result = ServerResponse.from(other).build();
StepVerifier.create(result).expectNextMatches(response -> HttpStatus.OK.equals(response.statusCode()) && "bar".equals(response.headers().getFirst("foo")) && cookie.equals(response.cookies().getFirst("foo"))).expectComplete().verify();
}
use of org.springframework.http.ResponseCookie in project spring-framework by spring-projects.
the class RouterFunctionsTests method toHttpHandlerHandlerReturnResponseStatusExceptionInResponseWriteTo.
@Test
public void toHttpHandlerHandlerReturnResponseStatusExceptionInResponseWriteTo() {
HandlerFunction<ServerResponse> handlerFunction = // Mono.<ServerResponse> is required for compilation in Eclipse
request -> Mono.just(new ServerResponse() {
@Override
public HttpStatus statusCode() {
return HttpStatus.OK;
}
@Override
public int rawStatusCode() {
return 200;
}
@Override
public HttpHeaders headers() {
return new HttpHeaders();
}
@Override
public MultiValueMap<String, ResponseCookie> cookies() {
return new LinkedMultiValueMap<>();
}
@Override
public Mono<Void> writeTo(ServerWebExchange exchange, Context context) {
return Mono.error(new ResponseStatusException(HttpStatus.NOT_FOUND, "Not found"));
}
});
RouterFunction<ServerResponse> routerFunction = RouterFunctions.route(RequestPredicates.all(), handlerFunction);
HttpHandler result = RouterFunctions.toHttpHandler(routerFunction);
assertThat(result).isNotNull();
MockServerHttpRequest httpRequest = MockServerHttpRequest.get("https://localhost").build();
MockServerHttpResponse httpResponse = new MockServerHttpResponse();
result.handle(httpRequest, httpResponse).block();
assertThat(httpResponse.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
}
Aggregations