List of usage examples for io.netty.handler.codec.http.cookie Cookie isSecure
boolean isSecure();
From source file:com.vmware.xenon.common.http.netty.CookieJar.java
License:Open Source License
/** * List cookies that apply for the given request URI. * * @param uri request URI// ww w .j ava 2s. c o m */ public Map<String, String> list(URI uri) { Map<String, String> result = new HashMap<>(); // Find cookies by the request URI String origin = buildOrigin(uri); Set<Cookie> byOrigin = this.cookiesByOrigin.get(origin); if (byOrigin != null) { for (Cookie cookie : byOrigin) { // Only add "secure" cookies if request URI has https scheme if (cookie.isSecure() && !uri.getScheme().equals(URI_SCHEME_HTTPS)) { continue; } result.put(cookie.name(), cookie.value()); } } return result; }
From source file:com.vmware.xenon.common.TestAuthentication.java
License:Open Source License
private void doAuthenticationServiceTokenRequest(VerificationHost host, boolean isSecure) throws Throwable { TestRequestSender sender = new TestRequestSender(host); host.log("Testing authenticationService token request"); // make a request to get the accessToken for the authentication service Operation requestOp = Operation.createGet(host, TestAuthenticationService.SELF_LINK).forceRemote(); Operation responseOp = sender.sendAndWait(requestOp); String cookieHeader = responseOp.getResponseHeader(SET_COOKIE_HEADER); assertNotNull(cookieHeader);/* w w w.j a va 2s. c o m*/ // assert the auth token cookie Cookie tokenCookie = ClientCookieDecoder.LAX.decode(cookieHeader); assertEquals(TestAuthenticationService.ACCESS_TOKEN, tokenCookie.value()); assertEquals(isSecure, tokenCookie.isSecure()); // assert the auth token header assertEquals(TestAuthenticationService.ACCESS_TOKEN, responseOp.getResponseHeader(Operation.REQUEST_AUTH_TOKEN_HEADER)); host.log("AuthenticationService token request is working"); }
From source file:io.vertx.ext.web.client.impl.CookieStoreImpl.java
License:Open Source License
@Override public Iterable<Cookie> get(Boolean ssl, String domain, String path) { assert domain != null && domain.length() > 0; String cleanPath;/*from www . j a v a 2 s . c om*/ { String uri = HttpUtils.removeDots(path); // Remoe query params if present int pos = uri.indexOf('?'); if (pos > -1) { uri = uri.substring(0, pos); } // Remoe frament identifier if present pos = uri.indexOf('#'); if (pos > -1) { uri = uri.substring(0, pos); } cleanPath = uri; } TreeMap<String, Cookie> matches = new TreeMap<>(); Consumer<Cookie> adder = c -> { if (ssl != Boolean.TRUE && c.isSecure()) { return; } if (c.path() != null && !cleanPath.equals(c.path())) { String cookiePath = c.path(); if (!cookiePath.endsWith("/")) { cookiePath += '/'; } if (!cleanPath.startsWith(cookiePath)) { return; } } matches.put(c.name(), c); }; for (Cookie c : noDomainCookies.values()) { adder.accept(c); } Key key = new Key(domain, "", ""); String prefix = key.domain.substring(0, 1); for (Entry<Key, Cookie> entry : domainCookies.tailMap(new Key(prefix, "", ""), true).entrySet()) { if (entry.getKey().domain.compareTo(key.domain) > 0) { break; } if (!key.domain.startsWith(entry.getKey().domain)) { continue; } adder.accept(entry.getValue()); } return matches.values(); }
From source file:org.atmosphere.nettosphere.BridgeRuntime.java
License:Apache License
private Set<javax.servlet.http.Cookie> getCookies(final HttpRequest request) { Set<javax.servlet.http.Cookie> result = new HashSet<javax.servlet.http.Cookie>(); String cookieHeader = request.headers().get("Cookie"); if (cookieHeader != null) { Set<io.netty.handler.codec.http.cookie.Cookie> cookies = ServerCookieDecoder.LAX.decode(cookieHeader); for (io.netty.handler.codec.http.cookie.Cookie cookie : cookies) { javax.servlet.http.Cookie c = new javax.servlet.http.Cookie(cookie.name(), cookie.value()); if (cookie.domain() != null) { c.setDomain(cookie.domain()); }/* w w w .j a v a 2 s . c o m*/ c.setHttpOnly(cookie.isHttpOnly()); c.setMaxAge((int) cookie.maxAge()); if (cookie.path() != null) { c.setPath(cookie.path()); } c.setSecure(cookie.isSecure()); result.add(c); } } return result; }
From source file:org.robotbrains.support.web.server.netty.NettyHttpRequest.java
License:Apache License
/** * Convert a Netty cookie to a Java HTTP cookie. * * @param cookie//from w ww.ja v a2 s . com * the Netty cookie * * @return the Java cookie */ private HttpCookie convertFromNettyCookie(Cookie cookie) { HttpCookie httpCookie = new HttpCookie(cookie.name(), cookie.value()); httpCookie.setDomain(cookie.domain()); httpCookie.setMaxAge(cookie.maxAge()); httpCookie.setPath(cookie.path()); httpCookie.setSecure(cookie.isSecure()); return httpCookie; }