460769 - ClientUpgradeRequest sends cookies in the wrong format

+ Simplifying HTTP Client "Cookie:" header based on rfcs
This commit is contained in:
Joakim Erdfelt 2015-03-06 15:19:03 -07:00
parent 9edd7c4b30
commit 2ceaf6e65c
2 changed files with 20 additions and 2 deletions

View File

@ -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");

View File

@ -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