Search in sources :

Example 1 with Cookie

use of io.netty.handler.codec.http.cookie.Cookie in project moco by dreamhead.

the class MocoCookieStandaloneTest method should_set_and_recognize_cookie_with_max_age.

@Test
public void should_set_and_recognize_cookie_with_max_age() throws IOException {
    runWithConfiguration("cookie.json");
    Cookie decodeCookie = getCookie("/cookie-with-max-age");
    assertThat(decodeCookie.name(), is("login"));
    assertThat(decodeCookie.value(), is("true"));
    assertThat(decodeCookie.maxAge(), is(3600L));
}
Also used : Cookie(io.netty.handler.codec.http.cookie.Cookie) Test(org.junit.Test)

Example 2 with Cookie

use of io.netty.handler.codec.http.cookie.Cookie in project moco by dreamhead.

the class MocoCookieStandaloneTest method should_set_and_recognize_cookie_with_domain.

@Test
public void should_set_and_recognize_cookie_with_domain() throws IOException {
    runWithConfiguration("cookie.json");
    Cookie decodeCookie = getCookie("/cookie-with-domain");
    assertThat(decodeCookie.name(), is("login"));
    assertThat(decodeCookie.value(), is("true"));
    assertThat(decodeCookie.domain(), is("github.com"));
}
Also used : Cookie(io.netty.handler.codec.http.cookie.Cookie) Test(org.junit.Test)

Example 3 with Cookie

use of io.netty.handler.codec.http.cookie.Cookie in project moco by dreamhead.

the class MocoCookieStandaloneTest method should_set_and_recognize_cookie.

@Test
public void should_set_and_recognize_cookie() throws IOException {
    runWithConfiguration("cookie.json");
    Cookie decodeCookie = getCookie("/cookie");
    assertThat(decodeCookie.name(), is("login"));
    assertThat(decodeCookie.value(), is("true"));
}
Also used : Cookie(io.netty.handler.codec.http.cookie.Cookie) Test(org.junit.Test)

Example 4 with Cookie

use of io.netty.handler.codec.http.cookie.Cookie in project moco by dreamhead.

the class MocoCookieStandaloneTest method should_set_and_recognize_cookie_with_secure.

@Test
public void should_set_and_recognize_cookie_with_secure() throws IOException {
    runWithConfiguration("cookie.json");
    Cookie decodeCookie = getCookie("/cookie-with-secure");
    assertThat(decodeCookie.name(), is("login"));
    assertThat(decodeCookie.value(), is("true"));
    assertThat(decodeCookie.isSecure(), is(true));
}
Also used : Cookie(io.netty.handler.codec.http.cookie.Cookie) Test(org.junit.Test)

Example 5 with Cookie

use of io.netty.handler.codec.http.cookie.Cookie in project ratpack by ratpack.

the class DefaultRequest method oneCookie.

public String oneCookie(String name) {
    Cookie found = null;
    List<Cookie> allFound = null;
    for (Cookie cookie : getCookies()) {
        if (cookie.name().equals(name)) {
            if (found == null) {
                found = cookie;
            } else if (allFound == null) {
                allFound = new ArrayList<>(2);
                allFound.add(found);
            } else {
                allFound.add(cookie);
            }
        }
    }
    if (found == null) {
        return null;
    } else if (allFound != null) {
        StringBuilder s = new StringBuilder("Multiple cookies with name '").append(name).append("': ");
        int i = 0;
        for (Cookie cookie : allFound) {
            s.append(cookie.toString());
            if (++i < allFound.size()) {
                s.append(", ");
            }
        }
        throw new IllegalStateException(s.toString());
    } else {
        return found.value();
    }
}
Also used : Cookie(io.netty.handler.codec.http.cookie.Cookie)

Aggregations

Cookie (io.netty.handler.codec.http.cookie.Cookie)45 DefaultCookie (io.netty.handler.codec.http.cookie.DefaultCookie)21 Test (org.junit.Test)19 DefaultHttpHeaders (io.netty.handler.codec.http.DefaultHttpHeaders)15 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)12 Charset (java.nio.charset.Charset)9 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)6 Test (org.testng.annotations.Test)5 HttpRequest (io.netty.handler.codec.http.HttpRequest)4 ByteBuf (io.netty.buffer.ByteBuf)3 LastHttpContent (io.netty.handler.codec.http.LastHttpContent)3 HttpResponseHeaders (org.asynchttpclient.HttpResponseHeaders)3 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)2 DefaultFullHttpResponse (io.netty.handler.codec.http.DefaultFullHttpResponse)2 FullHttpResponse (io.netty.handler.codec.http.FullHttpResponse)2 HttpContent (io.netty.handler.codec.http.HttpContent)2 QueryStringDecoder (io.netty.handler.codec.http.QueryStringDecoder)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Uri (org.asynchttpclient.uri.Uri)2