From ede831664207868e4a47907e2a65a1ba0ad7c60a Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Fri, 13 Mar 2009 12:39:22 +0000 Subject: [PATCH] Fixed a problem where the value of commentURL and port is not double-quoted --- .../netty/handler/codec/http/CookieEncoder.java | 14 ++++++++++++-- .../netty/handler/codec/http/HttpCodecUtil.java | 2 ++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jboss/netty/handler/codec/http/CookieEncoder.java b/src/main/java/org/jboss/netty/handler/codec/http/CookieEncoder.java index 0443b7dd03..9ddf5a6a36 100644 --- a/src/main/java/org/jboss/netty/handler/codec/http/CookieEncoder.java +++ b/src/main/java/org/jboss/netty/handler/codec/http/CookieEncoder.java @@ -104,16 +104,17 @@ public class CookieEncoder { if (encodingVersion == 2) { if (cookie.getCommentURL() != null) { - add(sb, CookieHeaderNames.COMMENTURL, QueryStringEncoder.encodeComponent(cookie.getCommentURL(), charset)); + addQuoted(sb, CookieHeaderNames.COMMENTURL, QueryStringEncoder.encodeComponent(cookie.getCommentURL(), charset)); } if(!cookie.getPorts().isEmpty()) { sb.append(CookieHeaderNames.PORT); sb.append((char) HttpCodecUtil.EQUALS); + sb.append((char) HttpCodecUtil.DOUBLE_QUOTE); for (int port: cookie.getPorts()) { sb.append(port); sb.append((char) HttpCodecUtil.COMMA); } - sb.setLength(sb.length() - 1); // Remove the trailing comma. + sb.setCharAt(sb.length() - 1, (char) HttpCodecUtil.DOUBLE_QUOTE); sb.append((char) HttpCodecUtil.SEMICOLON); } if (cookie.isDiscard()) { @@ -132,6 +133,15 @@ public class CookieEncoder { sb.append((char) HttpCodecUtil.SEMICOLON); } + private void addQuoted(StringBuffer sb, String name, String val) { + sb.append(name); + sb.append((char) HttpCodecUtil.EQUALS); + sb.append((char) HttpCodecUtil.DOUBLE_QUOTE); + sb.append(val); + sb.append((char) HttpCodecUtil.DOUBLE_QUOTE); + sb.append((char) HttpCodecUtil.SEMICOLON); + } + private void add(StringBuffer sb, String name, int val) { sb.append(name); sb.append((char) HttpCodecUtil.EQUALS); diff --git a/src/main/java/org/jboss/netty/handler/codec/http/HttpCodecUtil.java b/src/main/java/org/jboss/netty/handler/codec/http/HttpCodecUtil.java index 2971ef8dd1..991574d106 100644 --- a/src/main/java/org/jboss/netty/handler/codec/http/HttpCodecUtil.java +++ b/src/main/java/org/jboss/netty/handler/codec/http/HttpCodecUtil.java @@ -68,6 +68,8 @@ class HttpCodecUtil { */ static final byte COMMA = 44; + static final byte DOUBLE_QUOTE = '"'; + private HttpCodecUtil() { super(); }