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

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

Introduction

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

Prototype

void setSecure(boolean secure);

Source Link

Document

Sets the security getStatus of this Cookie

Usage

From source file:com.bay1ts.bay.core.Response.java

License:Apache License

/**
 * Adds cookie to the response. Can be invoked multiple times to insert more than one cookie.
 *
 * @param path     path of the cookie//from  w w  w.  j  a  v a2 s. co m
 * @param name     name of the cookie
 * @param value    value of the cookie
 * @param maxAge   max age of the cookie in seconds (negative for the not persistent cookie, zero - deletes the cookie)
 * @param secured  if true : cookie will be secured
 * @param httpOnly if true: cookie will be marked as http only
 */
public void cookie(String path, String name, String value, int maxAge, boolean secured, boolean httpOnly) {
    Cookie cookie = new DefaultCookie(name, value);
    cookie.setPath(path);
    cookie.setMaxAge(maxAge);
    cookie.setSecure(secured);
    cookie.setHttpOnly(httpOnly);
    response.headers().set(HttpHeaderNames.COOKIE, ServerCookieEncoder.STRICT.encode(cookie));
}

From source file:com.vmware.xenon.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:io.vertx.ext.web.client.SessionAwareWebClientTest.java

License:Open Source License

@Test
public void testCookieStore(TestContext context) {
    CookieStore store = CookieStore.build();
    Cookie c;

    c = new DefaultCookie("a", "1");
    store.put(c);/*from ww  w.  ja v a  2  s  .  c om*/

    c = new DefaultCookie("b", "2");
    c.setDomain("vertx.io");
    store.put(c);

    c = new DefaultCookie("c", "3");
    c.setDomain("www.vertx.io");
    c.setPath("/web-client");
    store.put(c);

    c = new DefaultCookie("d", "4");
    c.setPath("/web-client");
    store.put(c);

    c = new DefaultCookie("e", "5");
    c.setDomain("vertx.io");
    c.setSecure(true);
    store.put(c);

    c = new DefaultCookie("b", "20");
    c.setDomain("www.vertx.io");
    store.put(c);

    c = new DefaultCookie("b", "200");
    c.setDomain("www.vertx.io");
    c.setPath("/web-client");
    store.put(c);

    validate(context, store.get(false, "www.vertx.io", "/"), new String[] { "a", "b" },
            new String[] { "1", "20" });
    validate(context, store.get(false, "a.www.vertx.io", "/"), new String[] { "a", "b" },
            new String[] { "1", "20" });
    validate(context, store.get(false, "test.vertx.io", "/"), new String[] { "a", "b" },
            new String[] { "1", "2" });
    validate(context, store.get(false, "www.vertx.io", "/web-client"), new String[] { "a", "b", "c", "d" },
            new String[] { "1", "200", "3", "4" });
    validate(context, store.get(true, "test.vertx.io", "/"), new String[] { "a", "b", "e" },
            new String[] { "1", "2", "5" });
}

From source file:nikoladasm.aspark.ResponseImpl.java

License:Open Source License

@Override
public void cookie(String path, String name, String value, int maxAge, boolean secured, boolean httpOnly) {
    Cookie cookie = new DefaultCookie(name, value);
    cookie.setPath(path);/*from  w w w .j  a  va2  s . c  o m*/
    cookie.setMaxAge(maxAge);
    cookie.setSecure(secured);
    cookie.setHttpOnly(httpOnly);
    cookies.put(name, cookie);
}

From source file:org.robotbrains.support.web.server.netty.NettyHttpResponse.java

License:Apache License

/**
 * Create a Netty representation of a cookie.
 *
 * @param cookie//  ww  w .j a  va2 s . c  om
 *          the standard Java cookie
 *
 * @return the Netty cookie
 */
public static Cookie createNettyCookie(HttpCookie cookie) {
    Cookie nettyCookie = new DefaultCookie(cookie.getName(), cookie.getValue());
    nettyCookie.setDomain(cookie.getDomain());
    nettyCookie.setMaxAge((int) cookie.getMaxAge());
    nettyCookie.setPath(cookie.getPath());
    nettyCookie.setSecure(cookie.getSecure());

    return nettyCookie;
}

From source file:org.springframework.http.server.reactive.ReactorServerHttpResponse.java

License:Apache License

@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());
            }/*from w  ww  . java 2  s.  co  m*/
            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);
        }
    }
}

From source file:org.springframework.http.server.reactive.RxNettyServerHttpResponse.java

License:Apache License

@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());
            }//from w ww. j  a va 2 s. c  om
            httpCookie.getDomain().ifPresent(cookie::setDomain);
            httpCookie.getPath().ifPresent(cookie::setPath);
            cookie.setSecure(httpCookie.isSecure());
            cookie.setHttpOnly(httpCookie.isHttpOnly());
            this.response.addCookie(cookie);
        }
    }
}

From source file:ratpack.session.clientside.internal.ClientSideSessionStore.java

License:Apache License

private void invalidateCookie(String name) {
    Cookie cookie = response.get().expireCookie(name);
    if (cookieConfig.getPath() != null) {
        cookie.setPath(cookieConfig.getPath());
    }//w  w w  .jav a2 s  . c o  m
    if (cookieConfig.getDomain() != null) {
        cookie.setDomain(cookieConfig.getDomain());
    }
    cookie.setHttpOnly(cookieConfig.isHttpOnly());
    cookie.setSecure(cookieConfig.isSecure());
}

From source file:ratpack.session.clientside.internal.ClientSideSessionStore.java

License:Apache License

private void addCookie(String name, String value) {
    Cookie cookie = response.get().cookie(name, value);
    if (cookieConfig.getPath() != null) {
        cookie.setPath(cookieConfig.getPath());
    }// w  w  w  .ja  va  2  s .c o  m
    if (cookieConfig.getDomain() != null) {
        cookie.setDomain(cookieConfig.getDomain());
    }

    long expirySeconds = cookieConfig.getExpires() == null ? 0 : cookieConfig.getExpires().getSeconds();
    if (expirySeconds > 0) {
        cookie.setMaxAge(expirySeconds);
    }
    cookie.setHttpOnly(cookieConfig.isHttpOnly());
    cookie.setSecure(cookieConfig.isSecure());
}