Example usage for io.netty.handler.codec.http Cookie.Builder setPath

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

Introduction

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

Prototype

void setPath(String path);

Source Link

Document

Sets the path of this Cookie .

Usage

From source file:org.wisdom.framework.vertx.cookies.CookieHelper.java

License:Apache License

/**
 * Converts the Netty's cookie to a Wisdom's cookie.
 *
 * @param cookie the Netty's cookie/*from w w  w .ja va 2  s.c  o m*/
 * @return the Wisdom's cookie with the same metadata and content than the input cookie.
 */
public static Cookie convertNettyCookieToWisdomCookie(io.netty.handler.codec.http.Cookie cookie) {
    Preconditions.checkNotNull(cookie);
    String value = cookie.getValue();
    // Netty append some data at the end f the cookie:
    // -createdBy=wisdom&at=3+nov.+2013+11%3A52%3A15&___TS=1383475935779, path=/, maxAge=3600s, secure, HTTPOnly
    // We have to remove them
    // TODO Do we really need this ? It was probably related to the cookie encoding issue.
    if (value.contains(PATH)) {
        value = value.substring(0, value.indexOf(PATH));
    }

    Cookie.Builder builder = Cookie.builder(cookie.getName(), value);

    builder.setMaxAge(cookie.getMaxAge());

    if (cookie.getComment() != null) {
        builder.setComment(cookie.getComment());
    }

    if (cookie.getDomain() != null) {
        builder.setDomain(cookie.getDomain());
    }

    builder.setSecure(cookie.isSecure());

    if (cookie.getPath() != null) {
        builder.setPath(cookie.getPath());
    }

    builder.setHttpOnly(cookie.isHttpOnly());

    return builder.build();
}