jetty-9 some optimizations

This commit is contained in:
Greg Wilkins 2012-12-08 01:40:46 +11:00
parent 620d051087
commit f01da31a0a
6 changed files with 69 additions and 8 deletions

View File

@ -60,12 +60,12 @@ public class HttpField
CACHE.put(field);
CONTENT_TYPE.put(type,field);
for (String charset : new String[]{"UTF-8","iso-8859-1"})
for (String charset : new String[]{"UTF-8","ISO-8859-1"})
{
String type_charset=type+"; charset="+charset;
field=new HttpField(HttpHeader.CONTENT_TYPE,type_charset);
CACHE.put(field);
CACHE.put(HttpHeader.CONTENT_TYPE.asString()+": "+type+";charset="+charset,field);
CACHE.put(new HttpField(HttpHeader.CONTENT_TYPE,type+";charset="+charset));
CONTENT_TYPE.put(type_charset,field);
CONTENT_TYPE.put(type+";charset="+charset,field);
}
@ -225,6 +225,14 @@ public class HttpField
public boolean isSame(HttpField field)
{
return field!=null && (_header==field.getHeader() || _name.equalsIgnoreCase(field.getName()));
if (field==null)
return false;
if (field==this)
return true;
if (_header!=null && _header==field.getHeader())
return true;
if (_name.equalsIgnoreCase(field.getName()))
return true;
return false;
}
}

View File

@ -538,10 +538,14 @@ public class HttpFields implements Iterable<HttpField>
if (put)
_fields.remove(i);
else
{
_fields.set(i,field);
put=true;
}
}
}
_fields.add(field);
if (!put)
_fields.add(field);
}
/**

View File

@ -182,6 +182,7 @@ public class HttpFieldsTest
}
assertEquals(3, matches);
e = header.getValues("name1");
assertEquals(true, e.hasMoreElements());
assertEquals(e.nextElement(), "value1");

View File

@ -147,7 +147,7 @@ public class HttpParserTest
}
@Test
public void testHeaderParse() throws Exception
public void testHeaderParseCRLF() throws Exception
{
ByteBuffer buffer= BufferUtil.toBuffer(
"GET / HTTP/1.0\015\012" +
@ -194,6 +194,54 @@ public class HttpParserTest
assertEquals(9, _h);
}
@Test
public void testHeaderParseLF() throws Exception
{
ByteBuffer buffer= BufferUtil.toBuffer(
"GET / HTTP/1.0\n" +
"Host: localhost\n" +
"Header1: value1\n" +
"Header 2 : value 2a \n" +
" value 2b \n" +
"Header3: \n" +
"Header4 \n" +
" value4\n" +
"Server5 : notServer\n" +
"Host Header: notHost\n" +
"Connection: close\n" +
"Accept-Encoding: gzip, deflated\n" +
"Accept: unknown\n" +
"\n");
Handler handler = new Handler();
HttpParser parser= new HttpParser((HttpParser.RequestHandler)handler);
parseAll(parser,buffer);
assertEquals("GET", _methodOrVersion);
assertEquals("/", _uriOrStatus);
assertEquals("HTTP/1.0", _versionOrReason);
assertEquals("Host", _hdr[0]);
assertEquals("localhost", _val[0]);
assertEquals("Header1", _hdr[1]);
assertEquals("value1", _val[1]);
assertEquals("Header 2", _hdr[2]);
assertEquals("value 2a value 2b", _val[2]);
assertEquals("Header3", _hdr[3]);
assertEquals(null, _val[3]);
assertEquals("Header4", _hdr[4]);
assertEquals("value4", _val[4]);
assertEquals("Server5", _hdr[5]);
assertEquals("notServer", _val[5]);
assertEquals("Host Header", _hdr[6]);
assertEquals("notHost", _val[6]);
assertEquals("Connection", _hdr[7]);
assertEquals("close", _val[7]);
assertEquals("Accept-Encoding", _hdr[8]);
assertEquals("gzip, deflated", _val[8]);
assertEquals("Accept", _hdr[9]);
assertEquals("unknown", _val[9]);
assertEquals(9, _h);
}
@Test
public void testSplitHeaderParse() throws Exception
{

View File

@ -686,7 +686,7 @@ public class Response implements HttpServletResponse
encoding = StringUtil.__ISO_8859_1;
setCharacterEncoding(encoding);
}
if (StringUtil.__ISO_8859_1.equalsIgnoreCase(encoding))
{
_writer = new PrintWriter(new Iso88591HttpWriter(_out));

View File

@ -77,7 +77,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
protected static final String REQUEST2_HEADER =
"POST / HTTP/1.0\n" +
"Host: localhost\n" +
"Content-Type: text/xml;charset=ISO-8859-1\n" +
"Content-Type: text/xml; charset=ISO-8859-1\n" +
"Content-Length: ";
protected static final String REQUEST2_CONTENT =
"<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" +
@ -103,7 +103,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
+ "</nimbus>\n";
protected static final String RESPONSE2 =
"HTTP/1.1 200 OK\n" +
"Content-Type: text/xml;charset=ISO-8859-1\n" +
"Content-Type: text/xml; charset=ISO-8859-1\n" +
"Content-Length: " + RESPONSE2_CONTENT.getBytes().length + "\n" +
"Server: Jetty(" + Server.getVersion() + ")\n" +
"\n" +