use of cn.taketoday.http.HttpCookie in project today-infrastructure by TAKETODAY.
the class CookieIntegrationTests method basicTest.
@ParameterizedHttpServerTest
public void basicTest(HttpServer httpServer) throws Exception {
startServer(httpServer);
URI url = new URI("http://localhost:" + port);
String header = "SID=31d4d96e407aad42; lang=en-US";
ResponseEntity<Void> response = new RestTemplate().exchange(RequestEntity.get(url).header("Cookie", header).build(), Void.class);
Map<String, List<HttpCookie>> requestCookies = this.cookieHandler.requestCookies;
assertThat(requestCookies.size()).isEqualTo(2);
List<HttpCookie> list = requestCookies.get("SID");
assertThat(list.size()).isEqualTo(1);
assertThat(list.iterator().next().getValue()).isEqualTo("31d4d96e407aad42");
list = requestCookies.get("lang");
assertThat(list.size()).isEqualTo(1);
assertThat(list.iterator().next().getValue()).isEqualTo("en-US");
List<String> headerValues = response.getHeaders().get("Set-Cookie");
assertThat(headerValues.size()).isEqualTo(2);
List<String> cookie0 = splitCookie(headerValues.get(0));
assertThat(cookie0.remove("SID=31d4d96e407aad42")).as("SID").isTrue();
assertThat(cookie0.stream().map(String::toLowerCase)).containsExactlyInAnyOrder("path=/", "secure", "httponly");
List<String> cookie1 = splitCookie(headerValues.get(1));
assertThat(cookie1.remove("lang=en-US")).as("lang").isTrue();
assertThat(cookie1.stream().map(String::toLowerCase)).containsExactlyInAnyOrder("path=/", "domain=example.com");
}
use of cn.taketoday.http.HttpCookie in project today-infrastructure by TAKETODAY.
the class MockServerHttpRequestTests method cookieHeaderSet.
@Test
void cookieHeaderSet() {
HttpCookie foo11 = new HttpCookie("foo1", "bar1");
HttpCookie foo12 = new HttpCookie("foo1", "bar2");
HttpCookie foo21 = new HttpCookie("foo2", "baz1");
HttpCookie foo22 = new HttpCookie("foo2", "baz2");
MockServerHttpRequest request = MockServerHttpRequest.get("/").cookie(foo11, foo12, foo21, foo22).build();
assertThat(request.getCookies().get("foo1")).isEqualTo(Arrays.asList(foo11, foo12));
assertThat(request.getCookies().get("foo2")).isEqualTo(Arrays.asList(foo21, foo22));
assertThat(request.getHeaders().get(HttpHeaders.COOKIE)).isEqualTo(Arrays.asList("foo1=bar1", "foo1=bar2", "foo2=baz1", "foo2=baz2"));
}
use of cn.taketoday.http.HttpCookie in project today-framework by TAKETODAY.
the class LightRequestContext method doGetCookies.
@Override
protected HttpCookie[] doGetCookies() {
final HttpHeaders headers = request.getHeaders();
final List<String> allCookie = headers.get(HttpHeaders.COOKIE);
if (CollectionUtils.isEmpty(allCookie)) {
return EMPTY_COOKIES;
}
// TODO doGetCookies
return new HttpCookie[0];
}
use of cn.taketoday.http.HttpCookie in project today-framework by TAKETODAY.
the class CookieTokenResolver method getToken.
@Override
public String getToken(RequestContext context) {
final String cookieName = this.cookieName;
final HttpCookie cookie = context.getCookie(cookieName);
if (cookie == null) {
final ArrayList<HttpCookie> httpCookies = context.responseCookies();
for (final HttpCookie httpCookie : httpCookies) {
if (cookieName.equals(httpCookie.getName())) {
return httpCookie.getValue();
}
}
return null;
}
return cookie.getValue();
}
Aggregations