Example usage for io.netty.handler.codec.http Cookie isSecure

List of usage examples for io.netty.handler.codec.http Cookie isSecure

Introduction

In this page you can find the example usage for io.netty.handler.codec.http Cookie isSecure.

Prototype

boolean isSecure();

Source Link

Document

Checks to see if this Cookie is secure

Usage

From source file:com.vmware.dcp.common.http.netty.CookieJar.java

License:Open Source License

/**
 * List cookies that apply for the given request URI.
 *
 * @param uri request URI/*from w ww  .  ja  v a 2 s.  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: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++;//from   ww  w .ja va 2s . com
            }
            return cookiesArray;

        }
    }
    return new Cookie[0];
}

From source file:org.asynchttpclient.cookie.CookieDecoderTest.java

License:Open Source License

@Test(groups = "standalone")
public void testDecodingSingleCookieV0() {
    String cookieString = "myCookie=myValue;expires=XXX;path=/apathsomewhere;domain=.adomainsomewhere;secure;";
    cookieString = cookieString.replace("XXX",
            HttpHeaderDateFormat.get().format(new Date(System.currentTimeMillis() + 50000)));

    Cookie cookie = CookieDecoder.decode(cookieString);
    assertNotNull(cookie);/*  ww w  .j  a  v  a  2  s  . c  om*/
    assertEquals("myValue", cookie.getValue());
    assertEquals(".adomainsomewhere", cookie.getDomain());

    boolean fail = true;
    for (int i = 40; i <= 60; i++) {
        if (cookie.getMaxAge() == i) {
            fail = false;
            break;
        }
    }
    if (fail) {
        fail("expected: 50, actual: " + cookie.getMaxAge());
    }

    assertEquals(cookie.getPath(), "/apathsomewhere");
    assertTrue(cookie.isSecure());
}