Correctly format cookies. This fix some bug which lead to expiring of cookies to not work. See #426

This commit is contained in:
norman 2012-07-04 15:20:47 +02:00
parent 61a7c78a53
commit 1784283d29
4 changed files with 15 additions and 7 deletions

View File

@ -109,6 +109,7 @@ public final class ClientCookieEncoder {
}
buf.setCharAt(buf.length() - 1, (char) HttpConstants.DOUBLE_QUOTE);
buf.append((char) HttpConstants.SEMICOLON);
buf.append((char) HttpConstants.SP);
}
}
}

View File

@ -20,7 +20,7 @@ final class CookieEncoderUtil {
static String stripTrailingSeparator(StringBuilder buf) {
if (buf.length() > 0) {
buf.setLength(buf.length() - 1);
buf.setLength(buf.length() - 2);
}
return buf.toString();
}
@ -51,6 +51,7 @@ final class CookieEncoderUtil {
sb.append((char) HttpConstants.EQUALS);
sb.append(val);
sb.append((char) HttpConstants.SEMICOLON);
sb.append((char) HttpConstants.SP);
}
static void addQuoted(StringBuilder sb, String name, String val) {
@ -64,6 +65,7 @@ final class CookieEncoderUtil {
sb.append(val.replace("\\", "\\\\").replace("\"", "\\\""));
sb.append((char) HttpConstants.DOUBLE_QUOTE);
sb.append((char) HttpConstants.SEMICOLON);
sb.append((char) HttpConstants.SP);
}
static void add(StringBuilder sb, String name, long val) {
@ -71,6 +73,7 @@ final class CookieEncoderUtil {
sb.append((char) HttpConstants.EQUALS);
sb.append(val);
sb.append((char) HttpConstants.SEMICOLON);
sb.append((char) HttpConstants.SP);
}
private CookieEncoderUtil() {

View File

@ -83,10 +83,12 @@ public final class ServerCookieEncoder {
if (cookie.isSecure()) {
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) {
@ -109,10 +111,12 @@ public final class ServerCookieEncoder {
}
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);
}
}