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

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

Introduction

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

Prototype

void setSecure(boolean secure);

Source Link

Document

Sets the security getStatus of this Cookie

Usage

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

License:Open Source License

@Test
public void cookieMarkedAsSecure() throws URISyntaxException {
    URI uri = URI.create("https://domain.com/path");
    Cookie cookie = new DefaultCookie("key", "value");
    cookie.setSecure(true);
    this.cookieJar.add(uri, cookie);

    uri = URI.create("http://domain.com/otherpath");
    assertEquals(0, this.cookieJar.list(uri).size());

    uri = URI.create("https://domain.com/otherpath");
    assertEquals(1, this.cookieJar.list(uri).size());
}

From source file:fr.wseduc.webutils.request.CookieHelper.java

License:Apache License

public static void set(String name, String value, long timeout, String path, HttpServerRequest request) {
    Cookie cookie = new DefaultCookie(name, value);
    cookie.setMaxAge(timeout);//from w  ww  . j a v a  2  s .  c o  m
    cookie.setSecure("https".equals(Renders.getScheme(request)));
    if (path != null && !path.trim().isEmpty()) {
        cookie.setPath(path);
    }
    request.response().headers().set("Set-Cookie", ServerCookieEncoder.encode(cookie));
}

From source file:fr.wseduc.webutils.request.CookieHelper.java

License:Apache License

public void setSigned(String name, String value, long timeout, String path, HttpServerRequest request) {
    Cookie cookie = new DefaultCookie(name, value);
    cookie.setMaxAge(timeout);//from w w w  .j av a  2s  .  co  m
    cookie.setSecure("https".equals(Renders.getScheme(request)));
    if (path != null && !path.trim().isEmpty()) {
        cookie.setPath(path);
    }
    if (signKey != null) {
        try {
            signCookie(cookie);
        } catch (InvalidKeyException | NoSuchAlgorithmException | IllegalStateException
                | UnsupportedEncodingException e) {
            log.error(e);
            return;
        }
        request.response().headers().set("Set-Cookie", ServerCookieEncoder.encode(cookie));
    }
}

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 w ww. j a  v a 2s. c o m
            }
            return cookiesArray;

        }
    }
    return new Cookie[0];
}