Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Wilkins2012-05-23 09:49:21 +0000
committerGreg Wilkins2012-05-23 09:49:21 +0000
commit8b98e3918c1338cc11a34be749b774f0268390c1 (patch)
tree1920835368f156125fee1dcfb429f375a34c3ec2 /jetty-http
parent294150f485220216ccc7f891d0e2542d608f3009 (diff)
downloadorg.eclipse.jetty.project-8b98e3918c1338cc11a34be749b774f0268390c1.tar.gz
org.eclipse.jetty.project-8b98e3918c1338cc11a34be749b774f0268390c1.tar.xz
org.eclipse.jetty.project-8b98e3918c1338cc11a34be749b774f0268390c1.zip
jetty-9 more progress with server tests
Diffstat (limited to 'jetty-http')
-rw-r--r--jetty-http/pom.xml4
-rw-r--r--jetty-http/src/main/java/org/eclipse/jetty/http/HttpFields.java48
-rw-r--r--jetty-http/src/test/java/org/eclipse/jetty/http/HttpFieldsTest.java22
-rw-r--r--jetty-http/src/test/java/org/eclipse/jetty/http/HttpGeneratorServerTest.java10
4 files changed, 28 insertions, 56 deletions
diff --git a/jetty-http/pom.xml b/jetty-http/pom.xml
index 8942880b6e..e3be6ca356 100644
--- a/jetty-http/pom.xml
+++ b/jetty-http/pom.xml
@@ -22,8 +22,8 @@
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
+ <groupId>org.eclipse.jetty.toolchain</groupId>
+ <artifactId>jetty-test-helper</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpFields.java b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpFields.java
index 23f8dcfd86..cf44b05b19 100644
--- a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpFields.java
+++ b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpFields.java
@@ -288,7 +288,6 @@ public class HttpFields implements Iterable<HttpFields.Field>
/* -------------------------------------------------------------- */
private final ArrayList<Field> _fields = new ArrayList<Field>(20);
private final StringMap<Field> _names = new StringMap<Field>(true);
- private final int _maxCookieVersion;
/* ------------------------------------------------------------ */
/**
@@ -296,16 +295,6 @@ public class HttpFields implements Iterable<HttpFields.Field>
*/
public HttpFields()
{
- _maxCookieVersion=1;
- }
-
- /* ------------------------------------------------------------ */
- /**
- * Constructor.
- */
- public HttpFields(int maxCookieVersion)
- {
- _maxCookieVersion=maxCookieVersion;
}
@@ -820,7 +809,7 @@ public class HttpFields implements Iterable<HttpFields.Field>
final boolean isHttpOnly,
int version)
{
- String delim=_maxCookieVersion==0?"":__COOKIE_DELIM;
+ String delim=__COOKIE_DELIM;
// Check arguments
if (name == null || name.length() == 0)
@@ -835,23 +824,7 @@ public class HttpFields implements Iterable<HttpFields.Field>
if (value != null && value.length() > 0)
quoted|=QuotedStringTokenizer.quoteIfNeeded(buf, value, delim);
- // upgrade to version 1 cookies if quoted.
- if (quoted&&version==0 && _maxCookieVersion>=1)
- version=1;
-
- if (version>_maxCookieVersion)
- version=_maxCookieVersion;
-
- if (version > 0)
- {
- buf.append(";Version=");
- buf.append(version);
- if (comment != null && comment.length() > 0)
- {
- buf.append(";Comment=");
- QuotedStringTokenizer.quoteIfNeeded(buf, comment, delim);
- }
- }
+
if (path != null && path.length() > 0)
{
buf.append(";Path=");
@@ -875,15 +848,8 @@ public class HttpFields implements Iterable<HttpFields.Field>
else
formatCookieDate(buf, System.currentTimeMillis() + 1000L * maxAge);
- if (version >0)
- {
- buf.append(";Max-Age=");
- buf.append(maxAge);
- }
- }
- else if (version > 0)
- {
- buf.append(";Discard");
+ buf.append(";Max-Age=");
+ buf.append(maxAge);
}
if (isSecure)
@@ -891,6 +857,12 @@ public class HttpFields implements Iterable<HttpFields.Field>
if (isHttpOnly)
buf.append(";HttpOnly");
+ if (comment != null && comment.length() > 0)
+ {
+ buf.append(";Comment=");
+ QuotedStringTokenizer.quoteIfNeeded(buf, comment, delim);
+ }
+
name_value_params = buf.toString();
// remove existing set-cookie of same name
diff --git a/jetty-http/src/test/java/org/eclipse/jetty/http/HttpFieldsTest.java b/jetty-http/src/test/java/org/eclipse/jetty/http/HttpFieldsTest.java
index fb4bedeeda..7f0fd27064 100644
--- a/jetty-http/src/test/java/org/eclipse/jetty/http/HttpFieldsTest.java
+++ b/jetty-http/src/test/java/org/eclipse/jetty/http/HttpFieldsTest.java
@@ -16,6 +16,7 @@ package org.eclipse.jetty.http;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import java.nio.ByteBuffer;
@@ -26,7 +27,7 @@ import java.util.Set;
import org.eclipse.jetty.util.BufferUtil;
import org.junit.Assert;
import org.junit.Test;
-import org.junit.matchers.JUnitMatchers;
+import org.hamcrest.Matchers;
/**
*
@@ -111,9 +112,9 @@ public class HttpFieldsTest
buffer.flip();
String out = BufferUtil.toString(buffer);
- Assert.assertThat(out,JUnitMatchers.containsString(HttpHeader.CONNECTION+": "+HttpHeaderValue.KEEP_ALIVE));
- Assert.assertThat(out,JUnitMatchers.containsString(HttpHeader.TRANSFER_ENCODING+": "+HttpHeaderValue.CHUNKED));
- Assert.assertThat(out,JUnitMatchers.containsString(HttpHeader.CONTENT_ENCODING+": "+HttpHeaderValue.GZIP));
+ Assert.assertThat(out,Matchers.containsString(HttpHeader.CONNECTION+": "+HttpHeaderValue.KEEP_ALIVE));
+ Assert.assertThat(out,Matchers.containsString(HttpHeader.TRANSFER_ENCODING+": "+HttpHeaderValue.CHUNKED));
+ Assert.assertThat(out,Matchers.containsString(HttpHeader.CONTENT_ENCODING+": "+HttpHeaderValue.GZIP));
@@ -251,10 +252,10 @@ public class HttpFieldsTest
fields.clear();
fields.addSetCookie("everything","wrong","wrong","wrong",0,"to be replaced",true,true,0);
fields.addSetCookie("everything","value","domain","path",0,"comment",true,true,0);
- assertEquals("everything=value;Path=path;Domain=domain;Expires=Thu, 01-Jan-1970 00:00:00 GMT;Secure;HttpOnly",fields.getStringField("Set-Cookie"));
+ assertEquals("everything=value;Path=path;Domain=domain;Expires=Thu, 01-Jan-1970 00:00:00 GMT;Max-Age=0;Secure;HttpOnly;Comment=comment",fields.getStringField("Set-Cookie"));
Enumeration<String> e =fields.getValues("Set-Cookie");
assertTrue(e.hasMoreElements());
- assertEquals("everything=value;Path=path;Domain=domain;Expires=Thu, 01-Jan-1970 00:00:00 GMT;Secure;HttpOnly",e.nextElement());
+ assertEquals("everything=value;Path=path;Domain=domain;Expires=Thu, 01-Jan-1970 00:00:00 GMT;Max-Age=0;Secure;HttpOnly;Comment=comment",e.nextElement());
assertFalse(e.hasMoreElements());
assertEquals("Thu, 01 Jan 1970 00:00:00 GMT",fields.getStringField("Expires"));
@@ -262,8 +263,8 @@ public class HttpFieldsTest
fields.clear();
fields.addSetCookie("ev erything","va lue","do main","pa th",1,"co mment",true,true,2);
String setCookie=fields.getStringField("Set-Cookie");
- assertTrue(setCookie.startsWith("\"ev erything\"=\"va lue\";Version=1;Comment=\"co mment\";Path=\"pa th\";Domain=\"do main\";Expires="));
- assertTrue(setCookie.endsWith("GMT;Max-Age=1;Secure;HttpOnly"));
+ assertThat(setCookie,Matchers.startsWith("\"ev erything\"=\"va lue\";Path=\"pa th\";Domain=\"do main\";Expires="));
+ assertThat(setCookie,Matchers.endsWith(" GMT;Max-Age=1;Secure;HttpOnly;Comment=\"co mment\""));
fields.clear();
fields.addSetCookie("name","value",null,null,-1,null,false,false,0);
@@ -272,7 +273,6 @@ public class HttpFieldsTest
fields.clear();
fields.addSetCookie("name","v a l u e",null,null,-1,null,false,false,0);
setCookie=fields.getStringField("Set-Cookie");
- assertEquals(17,setCookie.indexOf("Version=1"));
fields.clear();
fields.addSetCookie("json","{\"services\":[\"cwa\", \"aa\"]}",null,null,-1,null,false,false,-1);
@@ -292,10 +292,10 @@ public class HttpFieldsTest
assertEquals("name=more;Domain=domain",e.nextElement());
assertEquals("foo=bob;Domain=domain",e.nextElement());
- fields=new HttpFields(0);
+ fields=new HttpFields();
fields.addSetCookie("name","value==",null,null,-1,null,false,false,0);
setCookie=fields.getStringField("Set-Cookie");
- assertEquals("name=value==",setCookie);
+ assertEquals("name=\"value==\"",setCookie);
}
diff --git a/jetty-http/src/test/java/org/eclipse/jetty/http/HttpGeneratorServerTest.java b/jetty-http/src/test/java/org/eclipse/jetty/http/HttpGeneratorServerTest.java
index 84831c3fc3..d39de010a8 100644
--- a/jetty-http/src/test/java/org/eclipse/jetty/http/HttpGeneratorServerTest.java
+++ b/jetty-http/src/test/java/org/eclipse/jetty/http/HttpGeneratorServerTest.java
@@ -13,16 +13,15 @@
package org.eclipse.jetty.http;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.not;
+import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.either;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
-import static org.junit.matchers.JUnitMatchers.containsString;
-import static org.junit.matchers.JUnitMatchers.either;
-import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
@@ -30,6 +29,7 @@ import java.util.List;
import org.eclipse.jetty.http.HttpGenerator.Action;
import org.eclipse.jetty.http.HttpGenerator.ResponseInfo;
import org.eclipse.jetty.util.BufferUtil;
+import org.hamcrest.Matchers;
import org.junit.Test;
/**

Back to the top