@Override public String getDomain() { return nettyCookie.domain(); }
private org.jooby.Cookie cookie(final Cookie c) { org.jooby.Cookie.Definition cookie = new org.jooby.Cookie.Definition(c.name(), c.value()); Optional.ofNullable(c.domain()).ifPresent(cookie::domain); Optional.ofNullable(c.path()).ifPresent(cookie::path); return cookie.toCookie(); }
@Override public MultiValueMap<String, ResponseCookie> getCookies() { MultiValueMap<String, ResponseCookie> result = new LinkedMultiValueMap<>(); this.response.cookies().values().stream().flatMap(Collection::stream) .forEach(cookie -> result.add(cookie.name(), ResponseCookie.from(cookie.name(), cookie.value()) .domain(cookie.domain()) .path(cookie.path()) .maxAge(cookie.maxAge()) .secure(cookie.isSecure()) .httpOnly(cookie.isHttpOnly()) .build())); return CollectionUtils.unmodifiableMultiValueMap(result); }
private void add(String requestDomain, String requestPath, Cookie cookie) { AbstractMap.SimpleEntry<String, Boolean> pair = cookieDomain(cookie.domain(), requestDomain); String keyDomain = pair.getKey(); boolean hostOnly = pair.getValue(); String keyPath = cookiePath(cookie.path(), requestPath); CookieKey key = new CookieKey(cookie.name().toLowerCase(), keyDomain, keyPath); if (hasCookieExpired(cookie, 0)) cookieJar.remove(key); else cookieJar.put(key, new StoredCookie(cookie, hostOnly, cookie.maxAge() != Cookie.UNDEFINED_MAX_AGE)); }
@Override public int compareTo(Cookie c) { int v = name().compareTo(c.name()); if (v != 0) { return v; } if (path() == null) { if (c.path() != null) { return -1; } } else if (c.path() == null) { return 1; } else { v = path().compareTo(c.path()); if (v != 0) { return v; } } if (domain() == null) { if (c.domain() != null) { return -1; } } else if (c.domain() == null) { return 1; } else { v = domain().compareToIgnoreCase(c.domain()); return v; } return 0; }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof Cookie)) { return false; } Cookie that = (Cookie) o; if (!name().equals(that.name())) { return false; } if (path() == null) { if (that.path() != null) { return false; } } else if (that.path() == null) { return false; } else if (!path().equals(that.path())) { return false; } if (domain() == null) { if (that.domain() != null) { return false; } } else { return domain().equalsIgnoreCase(that.domain()); } return true; }
@Override public MultiValueMap<String, ResponseCookie> getCookies() { MultiValueMap<String, ResponseCookie> result = new LinkedMultiValueMap<>(); this.response.cookies().values().stream().flatMap(Collection::stream) .forEach(cookie -> result.add(cookie.name(), ResponseCookie.from(cookie.name(), cookie.value()) .domain(cookie.domain()) .path(cookie.path()) .maxAge(cookie.maxAge()) .secure(cookie.isSecure()) .httpOnly(cookie.isHttpOnly()) .build())); return CollectionUtils.unmodifiableMultiValueMap(result); }
@Override public void run() throws IOException { org.apache.http.HttpResponse response = helper.getResponse(root()); String value = response.getFirstHeader(HttpHeaders.SET_COOKIE).getValue(); Cookie decodeCookie = ClientCookieDecoder.STRICT.decode(value); assertThat(decodeCookie.domain(), is("localhost")); } });
private MultiValueMap<String, ResponseCookie> initCookies() { final MultiValueMap<String, ResponseCookie> cookies = new LinkedMultiValueMap<>(); headers.getAll(HttpHeaderNames.SET_COOKIE) .stream() .map(ClientCookieDecoder.LAX::decode) .forEach(c -> cookies.add(c.name(), ResponseCookie.from(c.name(), c.value()) .maxAge(c.maxAge()) .domain(c.domain()) .path(c.path()) .secure(c.isSecure()) .httpOnly(c.isHttpOnly()) .build())); return cookies; }
@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")); }
harCookie.setValue(cookie.value()); harCookie.setDomain(cookie.domain()); harCookie.setHttpOnly(cookie.isHttpOnly()); harCookie.setPath(cookie.path());
/** * Parse netty cookie to {@link Cookie}. * * @param nettyCookie netty raw cookie instance */ private void parseCookie(io.netty.handler.codec.http.cookie.Cookie nettyCookie) { var cookie = new Cookie(); cookie.name(nettyCookie.name()); cookie.value(nettyCookie.value()); cookie.httpOnly(nettyCookie.isHttpOnly()); cookie.path(nettyCookie.path()); cookie.domain(nettyCookie.domain()); cookie.maxAge(nettyCookie.maxAge()); this.cookies.put(cookie.name(), cookie); }
/** * Parse netty cookie to {@link Cookie}. * * @param nettyCookie netty raw cookie instance */ private void parseCookie(io.netty.handler.codec.http.cookie.Cookie nettyCookie) { var cookie = new Cookie(); cookie.name(nettyCookie.name()); cookie.value(nettyCookie.value()); cookie.httpOnly(nettyCookie.isHttpOnly()); cookie.path(nettyCookie.path()); cookie.domain(nettyCookie.domain()); cookie.maxAge(nettyCookie.maxAge()); this.cookies.put(cookie.name(), cookie); }
@Override public String getDomain() { return nettyCookie.domain(); }
assertThat(setCookie.name()).isEqualTo("a"); assertThat(setCookie.value()).isEqualTo("1"); assertThat(setCookie.domain()).isEqualTo("http://localhost"); assertThat(setCookie.path()).isEqualTo("/"); assertThat(setCookie.maxAge()).isEqualTo(Duration.ofSeconds(60).getSeconds());
@Override public String getDomain() { return cookie.domain(); }
@Override public String getDomain() { return nettyCookie.domain(); }
private org.jooby.Cookie cookie(final Cookie c) { org.jooby.Cookie.Definition cookie = new org.jooby.Cookie.Definition(c.name(), c.value()); Optional.ofNullable(c.domain()).ifPresent(cookie::domain); Optional.ofNullable(c.path()).ifPresent(cookie::path); return cookie.toCookie(); }
private static ResponseCookie convert(Cookie cookie) { String value = cookie.wrap() ? quote(cookie.value()) : cookie.value(); return responseCookie(cookie.name(), value) .domain(cookie.domain()) .path(cookie.path()) .maxAge(cookie.maxAge()) .httpOnly(cookie.isHttpOnly()) .secure(cookie.isSecure()) .build(); }