Example usage for io.netty.handler.codec.http HttpConstants SP

List of usage examples for io.netty.handler.codec.http HttpConstants SP

Introduction

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

Prototype

byte SP

To view the source code for io.netty.handler.codec.http HttpConstants SP.

Click Source Link

Document

Horizontal space

Usage

From source file:divconq.http.multipart.HttpPostMultipartRequestDecoder.java

License:Apache License

/**
 * Clean the String from any unallowed character
 *
 * @return the cleaned String// ww w  .j a va2  s . c  o m
 */
private static String cleanString(String field) {
    StringBuilder sb = new StringBuilder(field.length());
    for (int i = 0; i < field.length(); i++) {
        char nextChar = field.charAt(i);
        if (nextChar == HttpConstants.COLON) {
            sb.append(HttpConstants.SP);
        } else if (nextChar == HttpConstants.COMMA) {
            sb.append(HttpConstants.SP);
        } else if (nextChar == HttpConstants.EQUALS) {
            sb.append(HttpConstants.SP);
        } else if (nextChar == HttpConstants.SEMICOLON) {
            sb.append(HttpConstants.SP);
        } else if (nextChar == HttpConstants.HT) {
            sb.append(HttpConstants.SP);
        } else if (nextChar == HttpConstants.DOUBLE_QUOTE) {
            // nothing added, just removes it
        } else {
            sb.append(nextChar);
        }
    }
    return sb.toString().trim();
}

From source file:org.ireland.jnetty.util.http.ServletServerCookieEncoder.java

License:Apache License

public static String encode(Cookie cookie) {
    if (cookie == null) {
        throw new NullPointerException("cookie");
    }/*from   w ww. jav a2 s  .c o m*/

    StringBuilder buf = new StringBuilder();

    add(buf, cookie.getName(), cookie.getValue());

    if (cookie.getMaxAge() != Long.MIN_VALUE) {
        if (cookie.getVersion() == 0) {
            addUnquoted(buf, CookieHeaderNames.EXPIRES, new HttpHeaderDateFormat()
                    .format(new Date(System.currentTimeMillis() + cookie.getMaxAge() * 1000L)));
        } else {
            add(buf, CookieHeaderNames.MAX_AGE, cookie.getMaxAge());
        }
    }

    if (cookie.getPath() != null) {
        if (cookie.getVersion() > 0) {
            add(buf, CookieHeaderNames.PATH, cookie.getPath());
        } else {
            addUnquoted(buf, CookieHeaderNames.PATH, cookie.getPath());
        }
    }

    if (cookie.getDomain() != null) {
        if (cookie.getVersion() > 0) {
            add(buf, CookieHeaderNames.DOMAIN, cookie.getDomain());
        } else {
            addUnquoted(buf, CookieHeaderNames.DOMAIN, cookie.getDomain());
        }
    }
    if (cookie.getSecure()) {
        buf.append(CookieHeaderNames.SECURE);
        buf.append((char) HttpConstants.SEMICOLON);
        buf.append((char) HttpConstants.SP);
    }
    if (cookie.isHttpOnly()) {
        buf.append(CookieHeaderNames.HTTPONLY);
        buf.append((char) HttpConstants.SEMICOLON);
        buf.append((char) HttpConstants.SP);
    }
    if (cookie.getVersion() >= 1) {
        if (cookie.getComment() != null) {
            add(buf, CookieHeaderNames.COMMENT, cookie.getComment());
        }

        add(buf, CookieHeaderNames.VERSION, 1);

        if (cookie.getPath() != null) {
            addQuoted(buf, CookieHeaderNames.COMMENTURL, cookie.getPath());
        }

        /*            if (!cookie.getPorts().isEmpty()) {
        buf.append(CookieHeaderNames.PORT);
        buf.append((char) HttpConstants.EQUALS);
        buf.append((char) HttpConstants.DOUBLE_QUOTE);
        for (int port: cookie.getPorts()) {
            buf.append(port);
            buf.append((char) HttpConstants.COMMA);
        }
        buf.setCharAt(buf.length() - 1, (char) HttpConstants.DOUBLE_QUOTE);
        buf.append((char) HttpConstants.SEMICOLON);
        buf.append((char) HttpConstants.SP);
                    }*/
        /*            if (cookie.isDiscard()) {
        buf.append(CookieHeaderNames.DISCARD);
        buf.append((char) HttpConstants.SEMICOLON);
        buf.append((char) HttpConstants.SP);
                    }*/
    }

    return stripTrailingSeparator(buf);
}

From source file:org.ireland.jnetty.util.http.ServletServerCookieEncoder.java

License:Apache License

static void addUnquoted(StringBuilder sb, String name, String val) {
    sb.append(name);/*from  w  w w.  ja  v a2  s  . co  m*/
    sb.append((char) HttpConstants.EQUALS);
    sb.append(val);
    sb.append((char) HttpConstants.SEMICOLON);
    sb.append((char) HttpConstants.SP);
}

From source file:org.ireland.jnetty.util.http.ServletServerCookieEncoder.java

License:Apache License

static void addQuoted(StringBuilder sb, String name, String val) {
    if (val == null) {
        val = "";
    }//from  ww w.j a  v  a2s  .  c  o m

    sb.append(name);
    sb.append((char) HttpConstants.EQUALS);
    sb.append((char) HttpConstants.DOUBLE_QUOTE);
    sb.append(val.replace("\\", "\\\\").replace("\"", "\\\""));
    sb.append((char) HttpConstants.DOUBLE_QUOTE);
    sb.append((char) HttpConstants.SEMICOLON);
    sb.append((char) HttpConstants.SP);
}

From source file:org.ireland.jnetty.util.http.ServletServerCookieEncoder.java

License:Apache License

static void add(StringBuilder sb, String name, long val) {
    sb.append(name);/* www.  j a va  2s  . c  o m*/
    sb.append((char) HttpConstants.EQUALS);
    sb.append(val);
    sb.append((char) HttpConstants.SEMICOLON);
    sb.append((char) HttpConstants.SP);
}