diff --git a/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/ClientUpgradeRequest.java b/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/ClientUpgradeRequest.java index b70cad7e171..ac5873dc5e5 100644 --- a/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/ClientUpgradeRequest.java +++ b/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/ClientUpgradeRequest.java @@ -168,7 +168,17 @@ public class ClientUpgradeRequest extends UpgradeRequest { request.append("; "); } - request.append(cookie.toString()); + + request.append(cookie.getName()).append("="); + if (cookie.getVersion() == 1) + { + // must be enclosed with quotes + request.append('"').append(cookie.getValue()).append('"'); + } + else + { + request.append(cookie.getValue()); + } needDelim = true; } request.append("\r\n"); diff --git a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/CookieTest.java b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/CookieTest.java index 9dfc87d3ae0..a68c245057f 100644 --- a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/CookieTest.java +++ b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/CookieTest.java @@ -19,6 +19,7 @@ package org.eclipse.jetty.websocket.client; import static org.hamcrest.Matchers.*; +import static org.junit.Assert.*; import java.net.CookieManager; import java.net.HttpCookie; @@ -104,6 +105,12 @@ public class CookieTest client.setCookieStore(cookieMgr.getCookieStore()); HttpCookie cookie = new HttpCookie("hello","world"); cookie.setPath("/"); + cookie.setVersion(0); + cookie.setMaxAge(100000); + cookieMgr.getCookieStore().add(server.getWsUri(),cookie); + + cookie = new HttpCookie("foo","bar is the word"); + cookie.setPath("/"); cookie.setMaxAge(100000); cookieMgr.getCookieStore().add(server.getWsUri(),cookie); @@ -117,7 +124,8 @@ public class CookieTest // client confirms upgrade and receipt of frame String serverCookies = confirmClientUpgradeAndCookies(clientSocket,clientConnectFuture,serverConn); - Assert.assertThat("Cookies seen at server side",serverCookies,containsString("hello=\"world\"")); + assertThat("Cookies seen at server side",serverCookies,containsString("hello=world")); + assertThat("Cookies seen at server side",serverCookies,containsString("foo=\"bar is the word\"")); } @Test