Java Code Examples for io.netty.handler.codec.http.cookie.Cookie#setPath()
The following examples show how to use
io.netty.handler.codec.http.cookie.Cookie#setPath() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReactorServerHttpResponse.java From spring-analysis-note with MIT License | 6 votes |
@Override protected void applyCookies() { for (String name : getCookies().keySet()) { for (ResponseCookie httpCookie : getCookies().get(name)) { Cookie cookie = new DefaultCookie(name, httpCookie.getValue()); if (!httpCookie.getMaxAge().isNegative()) { cookie.setMaxAge(httpCookie.getMaxAge().getSeconds()); } if (httpCookie.getDomain() != null) { cookie.setDomain(httpCookie.getDomain()); } if (httpCookie.getPath() != null) { cookie.setPath(httpCookie.getPath()); } cookie.setSecure(httpCookie.isSecure()); cookie.setHttpOnly(httpCookie.isHttpOnly()); this.response.addCookie(cookie); } } }
Example 2
Source File: ReactorServerHttpResponse.java From java-technology-stack with MIT License | 6 votes |
@Override protected void applyCookies() { for (String name : getCookies().keySet()) { for (ResponseCookie httpCookie : getCookies().get(name)) { Cookie cookie = new DefaultCookie(name, httpCookie.getValue()); if (!httpCookie.getMaxAge().isNegative()) { cookie.setMaxAge(httpCookie.getMaxAge().getSeconds()); } if (httpCookie.getDomain() != null) { cookie.setDomain(httpCookie.getDomain()); } if (httpCookie.getPath() != null) { cookie.setPath(httpCookie.getPath()); } cookie.setSecure(httpCookie.isSecure()); cookie.setHttpOnly(httpCookie.isHttpOnly()); this.response.addCookie(cookie); } } }
Example 3
Source File: HttpSessionManager.java From glowroot with Apache License 2.0 | 6 votes |
private CommonResponse createSession(String username, Set<String> roles, boolean ldap) throws Exception { String sessionId = new BigInteger(130, secureRandom).toString(32); ImmutableSession session = ImmutableSession.builder() .caseAmbiguousUsername(username) .ldap(ldap) .roles(roles) .lastRequest(clock.currentTimeMillis()) .build(); sessionMap.put(sessionId, session); String layoutJson = layoutService .getLayoutJson(session.createAuthentication(central, configRepository)); CommonResponse response = new CommonResponse(OK, MediaType.JSON_UTF_8, layoutJson); Cookie cookie = new DefaultCookie(configRepository.getWebConfig().sessionCookieName(), sessionId); cookie.setHttpOnly(true); cookie.setPath("/"); response.setHeader(HttpHeaderNames.SET_COOKIE, ServerCookieEncoder.STRICT.encode(cookie)); purgeExpiredSessions(); auditSuccessfulLogin(username); return response; }
Example 4
Source File: DefaultWebRes.java From krpc with Apache License 2.0 | 5 votes |
public DefaultWebRes addCookie(String name, String value) { String paramsStr = null; int p = value.indexOf("^"); if (p >= 0) { paramsStr = value.substring(p + 1); value = value.substring(0, p); } if (cookies == null) cookies = new ArrayList<>(); Cookie c = new DefaultCookie(name, value); if (paramsStr != null) { Map<String, String> params = Plugin.defaultSplitParams(paramsStr); if (params.containsKey("domain")) c.setDomain(params.get("domain")); if (params.containsKey("path")) c.setPath(params.get("path")); if (params.containsKey("maxAge")) c.setMaxAge(Long.parseLong(params.get("maxAge"))); if (params.containsKey("httpOnly")) c.setHttpOnly(Boolean.parseBoolean(params.get("httpOnly"))); else c.setHttpOnly(true); if (params.containsKey("secure")) c.setSecure(Boolean.parseBoolean(params.get("secure"))); if (params.containsKey("wrap")) c.setWrap(Boolean.parseBoolean(params.get("wrap"))); } cookies.add(c); return this; }
Example 5
Source File: DefaultCookieManager.java From redant with Apache License 2.0 | 5 votes |
@Override public void addCookie(String name, String value, String domain, long maxAge) { if (StrUtil.isNotBlank(name) && StrUtil.isNotBlank(value)) { Cookie cookie = new DefaultCookie(name, value); cookie.setPath("/"); if (domain != null && domain.trim().length() > 0) { cookie.setDomain(domain); } if (maxAge > 0) { cookie.setMaxAge(maxAge); } setCookie(cookie); } }
Example 6
Source File: DefaultCookieManager.java From redant with Apache License 2.0 | 5 votes |
@Override public boolean deleteCookie(String name) { Cookie cookie = getCookie(name); if (cookie != null) { cookie.setMaxAge(0); cookie.setPath("/"); setCookie(cookie); return true; } return false; }
Example 7
Source File: HttpResponse.java From blade with Apache License 2.0 | 5 votes |
@Override public Response cookie(@NonNull String name, @NonNull String value, int maxAge) { Cookie nettyCookie = new io.netty.handler.codec.http.cookie.DefaultCookie(name, value); nettyCookie.setPath("/"); nettyCookie.setMaxAge(maxAge); this.cookies.add(nettyCookie); return this; }
Example 8
Source File: HttpResponse.java From blade with Apache License 2.0 | 5 votes |
@Override public Response cookie(@NonNull String name, @NonNull String value, int maxAge, boolean secured) { Cookie nettyCookie = new io.netty.handler.codec.http.cookie.DefaultCookie(name, value); nettyCookie.setPath("/"); nettyCookie.setMaxAge(maxAge); nettyCookie.setSecure(secured); this.cookies.add(nettyCookie); return this; }
Example 9
Source File: HttpResponse.java From blade with Apache License 2.0 | 5 votes |
@Override public Response cookie(@NonNull String path, @NonNull String name, @NonNull String value, int maxAge, boolean secured) { Cookie nettyCookie = new io.netty.handler.codec.http.cookie.DefaultCookie(name, value); nettyCookie.setMaxAge(maxAge); nettyCookie.setSecure(secured); nettyCookie.setPath(path); this.cookies.add(nettyCookie); return this; }
Example 10
Source File: HttpSessionManager.java From glowroot with Apache License 2.0 | 5 votes |
void deleteSessionCookie(CommonResponse response) throws Exception { Cookie cookie = new DefaultCookie(configRepository.getWebConfig().sessionCookieName(), ""); cookie.setHttpOnly(true); cookie.setMaxAge(0); cookie.setPath("/"); response.setHeader(HttpHeaderNames.SET_COOKIE, ServerCookieEncoder.STRICT.encode(cookie)); }
Example 11
Source File: SessionAwareWebClientTest.java From vertx-web with Apache License 2.0 | 4 votes |
@Test public void testRequestIsPrepared(TestContext context) { prepareServer(context, req -> { req.response().headers().add("set-cookie", ServerCookieEncoder.STRICT.encode(new DefaultCookie("test", "toast"))); }); Consumer<HttpRequest<Buffer>> check = r -> { Async async = context.async(); Cookie c = new DefaultCookie("test", "localhost"); c.setPath("/"); client.cookieStore().remove(c); r.send(ar -> { async.complete(); validate(context, client.cookieStore().get(false, "localhost", "/"), new String[] { "test" }, new String[] { "toast" }); }); async.await(); }; check.accept(client.delete("/")); check.accept(client.delete("localhost", "/")); check.accept(client.delete(PORT, "localhost", "/")); check.accept(client.deleteAbs("http://localhost/")); check.accept(client.get("/")); check.accept(client.get("localhost", "/")); check.accept(client.get(PORT, "localhost", "/")); check.accept(client.getAbs("http://localhost/")); check.accept(client.head("/")); check.accept(client.head("localhost", "/")); check.accept(client.head(PORT, "localhost", "/")); check.accept(client.headAbs("http://localhost/")); check.accept(client.patch("/")); check.accept(client.patch("localhost", "/")); check.accept(client.patch(PORT, "localhost", "/")); check.accept(client.patchAbs("http://localhost/")); check.accept(client.post("/")); check.accept(client.post("localhost", "/")); check.accept(client.post(PORT, "localhost", "/")); check.accept(client.postAbs("http://localhost/")); check.accept(client.put("/")); check.accept(client.put("localhost", "/")); check.accept(client.put(PORT, "localhost", "/")); check.accept(client.putAbs("http://localhost/")); check.accept(client.request(HttpMethod.GET, new RequestOptions())); check.accept(client.request(HttpMethod.GET, "/")); check.accept(client.request(HttpMethod.GET, "localhost", "/")); check.accept(client.request(HttpMethod.GET, PORT, "localhost", "/")); check.accept(client.requestAbs(HttpMethod.GET, "http://localhost/")); }