List of usage examples for io.netty.handler.codec.http Cookie getDomain
@Deprecated String getDomain();
From source file:com.mastfrog.acteur.wicket.adapters.CookieConverter.java
License:Open Source License
@Override public Cookie unconvert(javax.servlet.http.Cookie t) { if (t instanceof CookieAdapter) { return ((CookieAdapter) t).cookie; } else {// w w w . ja va 2 s.c o m DefaultCookie dc = new DefaultCookie(t.getName(), t.getValue()); dc.setComment(t.getComment()); dc.setMaxAge(t.getMaxAge()); dc.setDomain(t.getDomain()); dc.setVersion(t.getVersion()); return dc; } }
From source file:com.mastfrog.netty.http.client.CookieStore.java
License:Open Source License
void decorate(HttpRequest req) { URL url;/*from w w w .j ava2 s . c o m*/ if (!req.getUri().contains("://")) { String host = req.headers().get(Headers.HOST.name()); url = URL.builder().setPath(req.getUri()).setHost(host).create(); } else { url = URL.parse(req.getUri()); } Lock readLock = lock.readLock(); readLock.lock(); try { List<Cookie> toSend = new ArrayList<>(); for (Cookie cookie : cookies) { if (checkDomain) { if (cookie.getDomain() != null && !cookie.getDomain().equals(url.getHost().toString())) { continue; } } if (checkPath) { String pth = cookie.getPath(); if (pth != null) { String compare = url.getPath().toStringWithLeadingSlash(); if (!"/".equals(pth) && !"".equals(pth) && !compare.equals(pth) && !compare.startsWith(pth)) { continue; } } } toSend.add(cookie); } if (!toSend.isEmpty()) { for (Cookie ck : toSend) { String headerValue = Headers.COOKIE.toString(new Cookie[] { ck }); req.headers().add(Headers.COOKIE.name(), headerValue); } } } finally { readLock.unlock(); } }
From source file:com.titilink.camel.rest.common.AdapterRestletUtil.java
License:LGPL
/** * ?Cookie/*from ww w. ja v a2s . co m*/ * * @param cookie * @return */ public static org.restlet.data.Cookie parseToRestletCookie(Cookie cookie) { if (null == cookie) { LOGGER.error("cookie=null"); return null; } org.restlet.data.Cookie restletCookie = new org.restlet.data.Cookie(); restletCookie.setDomain(cookie.getDomain()); restletCookie.setVersion(cookie.getVersion()); restletCookie.setName(cookie.getName()); restletCookie.setValue(cookie.getValue()); restletCookie.setPath(cookie.getPath()); return restletCookie; }
From source file:fr.wseduc.webutils.request.CookieHelper.java
License:Apache License
private void signCookie(Cookie cookie) throws InvalidKeyException, NoSuchAlgorithmException, IllegalStateException, UnsupportedEncodingException { String signature = HmacSha1//ww w.ja v a 2 s. c om .sign(cookie.getDomain() + cookie.getName() + cookie.getPath() + cookie.getValue(), signKey); cookie.setValue(cookie.getValue() + ":" + signature); }
From source file:fr.wseduc.webutils.request.CookieHelper.java
License:Apache License
public String getSigned(String name, String path, HttpServerRequest request) { if (request.headers().get("Cookie") != null) { Set<Cookie> cookies = CookieDecoder.decode(request.headers().get("Cookie")); for (Cookie c : cookies) { if (c.getName().equals(name) && c.getValue().contains(":")) { int idx = c.getValue().lastIndexOf(":"); if (idx > c.getValue().length() - 1) continue; String value = c.getValue().substring(0, idx); String signature = c.getValue().substring(idx + 1); String calcSign = null; String cookiePath = path; if (cookiePath == null || cookiePath.trim().isEmpty()) { cookiePath = c.getPath(); }/*from w w w. j a v a2s.c om*/ try { calcSign = HmacSha1.sign(c.getDomain() + c.getName() + cookiePath + value, signKey); } catch (InvalidKeyException | NoSuchAlgorithmException | IllegalStateException | UnsupportedEncodingException e) { } if (calcSign != null && calcSign.equals(signature)) { return value; } } } } return null; }
From source file:io.nebo.container.NettyHttpServletRequest.java
License:Apache License
@Override public Cookie[] getCookies() { String cookieString = this.request.headers().get(COOKIE); if (cookieString != null) { Set<io.netty.handler.codec.http.Cookie> cookies = CookieDecoder.decode(cookieString); if (!cookies.isEmpty()) { Cookie[] cookiesArray = new Cookie[cookies.size()]; int index = 0; for (io.netty.handler.codec.http.Cookie c : cookies) { Cookie cookie = new Cookie(c.getName(), c.getValue()); cookie.setComment(c.getComment()); if (c.getDomain() != null) cookie.setDomain(c.getDomain()); cookie.setMaxAge((int) c.getMaxAge()); cookie.setPath(c.getPath()); cookie.setSecure(c.isSecure()); cookie.setVersion(c.getVersion()); cookiesArray[index] = cookie; index++;/* w w w .j a v a 2 s .c o m*/ } return cookiesArray; } } return new Cookie[0]; }
From source file:io.reactivex.netty.protocol.http.client.CookieTest.java
License:Apache License
@Test public void testGetCookie() throws Exception { DefaultHttpResponse nettyResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.NOT_FOUND); String cookie1Name = "PREF"; String cookie1Value = "ID=a95756377b78e75e:FF=0:TM=1392709628:LM=1392709628:S=a5mOVvTB7DBkexgi"; String cookie1Domain = ".google.com"; String cookie1Path = "/"; String cookie1Header = cookie1Name + '=' + cookie1Value + "; expires=Thu, 18-Feb-2016 07:47:08 GMT; path=" + cookie1Path + "; domain=" + cookie1Domain; nettyResponse.headers().add(HttpHeaders.Names.SET_COOKIE, cookie1Header); HttpClientResponse<ByteBuf> response = new HttpClientResponse<ByteBuf>(nettyResponse, PublishSubject.<ByteBuf>create()); Map<String, Set<Cookie>> cookies = response.getCookies(); Assert.assertNotNull("Cookies are null.", cookies); Assert.assertEquals("Cookies are empty.", 1, cookies.size()); Set<Cookie> cookies1 = cookies.get(cookie1Name); Assert.assertNotNull("No cookies found with name: " + cookie1Name, cookies1); Assert.assertEquals("Unexpected number of cookies found.", 1, cookies1.size()); Cookie cookieFound = cookies1.iterator().next(); Assert.assertEquals("unexpected cookie name.", cookie1Name, cookieFound.getName()); Assert.assertEquals("unexpected cookie value.", cookie1Value, cookieFound.getValue()); Assert.assertEquals("unexpected cookie path.", cookie1Path, cookieFound.getPath()); Assert.assertEquals("unexpected cookie domain.", cookie1Domain, cookieFound.getDomain()); }
From source file:io.reactivex.netty.protocol.http.client.CookieTest.java
License:Apache License
@Test public void testSetCookie() throws Exception { DefaultHttpRequest nettyRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, ""); String cookie1Name = "PREF"; String cookie1Value = "ID=a95756377b78e75e:FF=0:TM=1392709628:LM=1392709628:S=a5mOVvTB7DBkexgi"; String cookie1Domain = ".google.com"; String cookie1Path = "/"; Cookie cookie = new DefaultCookie(cookie1Name, cookie1Value); cookie.setPath(cookie1Path);//from w w w .j a va 2 s.c o m cookie.setDomain(cookie1Domain); new HttpClientRequest<ByteBuf>(nettyRequest).withCookie(cookie); String cookieHeader = nettyRequest.headers().get(HttpHeaders.Names.COOKIE); Assert.assertNotNull("No cookie header found.", cookieHeader); Set<Cookie> decodeCookies = CookieDecoder.decode(cookieHeader); Assert.assertNotNull("No cookie found with name.", decodeCookies); Assert.assertEquals("Unexpected number of cookies.", 1, decodeCookies.size()); Cookie decodedCookie = decodeCookies.iterator().next(); Assert.assertEquals("Unexpected cookie name.", cookie1Name, decodedCookie.getName()); Assert.assertEquals("Unexpected cookie path.", cookie1Path, decodedCookie.getPath()); Assert.assertEquals("Unexpected cookie domain.", cookie1Domain, decodedCookie.getDomain()); }
From source file:org.asynchttpclient.cookie.CookieDecoderTest.java
License:Open Source License
@Test(groups = "standalone") public void testDecodeUnquoted() { Cookie cookie = CookieDecoder.decode("foo=value; domain=/; path=/"); assertNotNull(cookie);/*from ww w .j a va 2 s . c o m*/ assertEquals(cookie.getValue(), "value"); assertEquals(cookie.isWrap(), false); assertEquals(cookie.getDomain(), "/"); assertEquals(cookie.getPath(), "/"); }
From source file:org.asynchttpclient.cookie.CookieDecoderTest.java
License:Open Source License
@Test(groups = "standalone") public void testIgnoreEmptyDomain() { Cookie cookie = CookieDecoder .decode("sessionid=OTY4ZDllNTgtYjU3OC00MWRjLTkzMWMtNGUwNzk4MTY0MTUw;Domain=;Path=/"); assertNull(cookie.getDomain()); }