use of org.springframework.http.HttpCookie in project spring-framework by spring-projects.
the class HttpHandlerConnector method adaptRequest.
private ServerHttpRequest adaptRequest(MockClientHttpRequest request, Publisher<DataBuffer> body) {
HttpMethod method = request.getMethod();
URI uri = request.getURI();
HttpHeaders headers = request.getHeaders();
MultiValueMap<String, HttpCookie> cookies = request.getCookies();
return MockServerHttpRequest.method(method, uri).headers(headers).cookies(cookies).body(body);
}
use of org.springframework.http.HttpCookie in project spring-framework by spring-projects.
the class HttpHandlerConnectorTests method adaptRequest.
@Test
public void adaptRequest() throws Exception {
TestHttpHandler handler = new TestHttpHandler(response -> {
response.setStatusCode(HttpStatus.OK);
return response.setComplete();
});
new HttpHandlerConnector(handler).connect(HttpMethod.POST, URI.create("/custom-path"), request -> {
request.getHeaders().put("custom-header", Arrays.asList("h0", "h1"));
request.getCookies().add("custom-cookie", new HttpCookie("custom-cookie", "c0"));
return request.writeWith(Mono.just(toDataBuffer("Custom body")));
}).block(Duration.ofSeconds(5));
MockServerHttpRequest request = (MockServerHttpRequest) handler.getSavedRequest();
assertEquals(HttpMethod.POST, request.getMethod());
assertEquals("/custom-path", request.getURI().toString());
assertEquals(Arrays.asList("h0", "h1"), request.getHeaders().get("custom-header"));
assertEquals(new HttpCookie("custom-cookie", "c0"), request.getCookies().getFirst("custom-cookie"));
DataBuffer buffer = request.getBody().blockFirst(Duration.ZERO);
assertEquals("Custom body", DataBufferTestUtils.dumpString(buffer, UTF_8));
}
use of org.springframework.http.HttpCookie in project spring-framework by spring-projects.
the class RxNettyServerHttpRequest method initCookies.
@Override
protected MultiValueMap<String, HttpCookie> initCookies() {
MultiValueMap<String, HttpCookie> cookies = new LinkedMultiValueMap<>();
for (String name : this.request.getCookies().keySet()) {
for (Cookie cookie : this.request.getCookies().get(name)) {
HttpCookie httpCookie = new HttpCookie(name, cookie.value());
cookies.add(name, httpCookie);
}
}
return cookies;
}
use of org.springframework.http.HttpCookie in project spring-framework by spring-projects.
the class ServletServerHttpRequest method initCookies.
@Override
protected MultiValueMap<String, HttpCookie> initCookies() {
MultiValueMap<String, HttpCookie> httpCookies = new LinkedMultiValueMap<>();
Cookie[] cookies;
synchronized (this.cookieLock) {
cookies = this.request.getCookies();
}
if (cookies != null) {
for (Cookie cookie : cookies) {
String name = cookie.getName();
HttpCookie httpCookie = new HttpCookie(name, cookie.getValue());
httpCookies.add(name, httpCookie);
}
}
return httpCookies;
}
use of org.springframework.http.HttpCookie in project spring-framework by spring-projects.
the class UndertowServerHttpRequest method initCookies.
@Override
protected MultiValueMap<String, HttpCookie> initCookies() {
MultiValueMap<String, HttpCookie> cookies = new LinkedMultiValueMap<>();
for (String name : this.exchange.getRequestCookies().keySet()) {
Cookie cookie = this.exchange.getRequestCookies().get(name);
HttpCookie httpCookie = new HttpCookie(name, cookie.getValue());
cookies.add(name, httpCookie);
}
return cookies;
}
Aggregations