From 510a270cb4b7366b0835aaf669c096e2f88f95f9 Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Fri, 13 Mar 2009 15:17:11 +0000 Subject: [PATCH] CookieEncoder should not use a Map but use a Set because cookie name might be duplicate --- .../handler/codec/http/CookieEncoder.java | 25 +++++++------------ 1 file changed, 9 insertions(+), 16 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 dc13dfe0cd..ca88ef292b 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 @@ -21,12 +21,9 @@ */ package org.jboss.netty.handler.codec.http; -import java.util.Collection; import java.util.Date; -import java.util.Map; -import java.util.TreeMap; - -import org.jboss.netty.util.CaseIgnoringComparator; +import java.util.Set; +import java.util.TreeSet; /** * @author The Netty Project (netty-dev@lists.jboss.org) @@ -36,7 +33,7 @@ import org.jboss.netty.util.CaseIgnoringComparator; */ public class CookieEncoder { - private final Map cookies = new TreeMap(CaseIgnoringComparator.INSTANCE); + private final Set cookies = new TreeSet(); private final String charset; @@ -51,23 +48,19 @@ public class CookieEncoder { this.charset = charset; } - public void addCookie(String name, String val) { - cookies.put(name, new DefaultCookie(name, val)); + public void addCookie(String name, String value) { + cookies.add(new DefaultCookie(name, value)); } public void addCookie(Cookie cookie) { - cookies.put(cookie.getName(), cookie); + cookies.add(cookie); } public String encode() { StringBuffer sb = new StringBuffer(); - Collection cookieNames = cookies.keySet(); - if (cookieNames.isEmpty()) { - return null; - } - for (String cookieName : cookieNames) { - Cookie cookie = cookies.get(cookieName); - add(sb, cookieName, QueryStringEncoder.encodeComponent(cookie.getValue(), charset)); + + for (Cookie cookie: cookies) { + add(sb, cookie.getName(), QueryStringEncoder.encodeComponent(cookie.getValue(), charset)); if (cookie.getMaxAge() >= 0) { if (cookie.getVersion() == 0) {