use of io.netty.handler.codec.http.cookie.Cookie in project riposte by Nike-Inc.
the class ChunkedResponseInfoTest method builder_works_as_expected_for_all_fields.
@Test
public void builder_works_as_expected_for_all_fields() {
// given
ChunkedResponseInfo.ChunkedResponseInfoBuilder builder = ResponseInfo.newChunkedResponseBuilder();
int statusCode = 42;
HttpHeaders headers = mock(HttpHeaders.class);
String mimeType = UUID.randomUUID().toString();
Charset encoding = CharsetUtil.US_ASCII;
Set<Cookie> cookies = mock(Set.class);
boolean preventCompressedOutput = Math.random() > 0.5;
// when
ChunkedResponseInfo responseInfo = builder.withHttpStatusCode(statusCode).withHeaders(headers).withDesiredContentWriterMimeType(mimeType).withDesiredContentWriterEncoding(encoding).withCookies(cookies).withPreventCompressedOutput(preventCompressedOutput).build();
// then
assertThat(responseInfo.getHttpStatusCode(), is(statusCode));
assertThat(responseInfo.getHeaders(), is(headers));
assertThat(responseInfo.getDesiredContentWriterMimeType(), is(mimeType));
assertThat(responseInfo.getDesiredContentWriterEncoding(), is(encoding));
assertThat(responseInfo.getCookies(), is(cookies));
assertThat(responseInfo.isPreventCompressedOutput(), is(preventCompressedOutput));
}
use of io.netty.handler.codec.http.cookie.Cookie in project riposte by Nike-Inc.
the class HttpUtilsTest method extractCookies_handles_cookie_values_leniently.
@Test
public void extractCookies_handles_cookie_values_leniently() {
// given
//these are cookie values seen in the wild...
Cookie cookie1 = new DefaultCookie(UUID.randomUUID().toString(), "2094%3Az%7C2021%3Ab");
Cookie cookie2 = new DefaultCookie(UUID.randomUUID().toString(), "geoloc=cc=US,rc=OR,tp=vhigh,tz=PST,la=45.4978,lo=-122.6937,bw=5000");
Cookie cookie3 = new DefaultCookie(UUID.randomUUID().toString(), "\"dm=n.com&si=27431295-a282-4745-8cd5-542e7fce" + "429e&ss=1477551008358&sl=76&tt=437632&obo=12&sh=1477552753923%3D76%3A12%3A437632%2C1477552698670%3D75%3" + "A12%3A429879%2C1477552677137%3D74%3A12%3A426596%2C1477552672564%3D73%3A12%3A425585%2C1477552669893%3D72" + "%3A12%3A423456&bcn=%2F%2F3408178b.mpstat.us%2F&ld=1477552753923&r=http%3A%2F%2Fwww.nike.com%2Fbe%2Fde_de%" + "2F&ul=1477552756811\"");
HttpHeaders headers = new DefaultHttpHeaders().add(HttpHeaders.Names.COOKIE, ClientCookieEncoder.LAX.encode(cookie1, cookie2, cookie3));
HttpRequest nettyRequestMock = mock(HttpRequest.class);
doReturn(headers).when(nettyRequestMock).headers();
// when
Set<Cookie> extractedCookies = HttpUtils.extractCookies(nettyRequestMock);
// then
assertThat(extractedCookies.contains(cookie1), is(true));
assertThat(extractedCookies.contains(cookie2), is(true));
assertThat(extractedCookies.contains(cookie3), is(true));
}
use of io.netty.handler.codec.http.cookie.Cookie in project moco by dreamhead.
the class MocoCookieStandaloneTest method should_set_and_recognize_cookie_with_http_only.
@Test
public void should_set_and_recognize_cookie_with_http_only() throws IOException {
runWithConfiguration("cookie.json");
Cookie decodeCookie = getCookie("/cookie-with-http-only");
assertThat(decodeCookie.name(), is("login"));
assertThat(decodeCookie.value(), is("true"));
assertThat(decodeCookie.isHttpOnly(), is(true));
}
use of io.netty.handler.codec.http.cookie.Cookie in project moco by dreamhead.
the class MocoCookieStandaloneTest method should_set_and_recognize_cookie_with_path.
@Test
public void should_set_and_recognize_cookie_with_path() throws IOException {
runWithConfiguration("cookie.json");
Cookie decodeCookie = getCookie("/cookie-with-path");
assertThat(decodeCookie.name(), is("login"));
assertThat(decodeCookie.value(), is("true"));
assertThat(decodeCookie.path(), is("/"));
}
use of io.netty.handler.codec.http.cookie.Cookie in project ratpack by ratpack.
the class DefaultResponse method cookie.
public Cookie cookie(String name, String value) {
Cookie cookie = new DefaultCookie(name, value);
getCookies().add(cookie);
return cookie;
}
Aggregations