jicarilla-sandbox/platform/components/http/impl/src/test/org/jicarilla/http/test HTTPParserImplTestCase.java,1.7,1.8
Leo Simons <[email protected]>
| Newsgroups | gmane.comp.java.jicarilla.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/jicarilla/jicarilla-sandbox/platform/components/http/impl/src/test/org/jicarilla/http/test
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7227/platform/components/http/impl/src/test/org/jicarilla/http/test
Modified Files:
HTTPParserImplTestCase.java
Log Message:
finish support for trailers
Index: HTTPParserImplTestCase.java
===================================================================
RCS file: /cvsroot/jicarilla/jicarilla-sandbox/platform/components/http/impl/src/test/org/jicarilla/http/test/HTTPParserImplTestCase.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- HTTPParserImplTestCase.java 3 Apr 2004 10:13:24 -0000 1.7
+++ HTTPParserImplTestCase.java 4 Apr 2004 14:16:44 -0000 1.8
@@ -498,6 +498,7 @@
// body
"12345";
+
doParse( request );
errorHandlerControl.verify();
@@ -610,7 +611,7 @@
handlerControl.verify();
}
- /** @todo support chunked transfer coding */
+ /* obsolete
public void testParseChunkedBody() throws Exception
{
handler.newMessage();
@@ -645,7 +646,7 @@
errorHandlerControl.verify();
handlerControl.verify();
- }
+ }*/
// ----------------------------------------------------------------------
// Multi-buffer Tests
@@ -871,7 +872,7 @@
"GET /" + Iso646.BELL + "bla HTTP/1.0" +
HTTPEncoding.CR + HTTPEncoding.LF +
HTTPEncoding.CR + HTTPEncoding.LF;
-
+
try
{
doParse( request );
@@ -1251,7 +1252,7 @@
handlerControl.verify();
}
- public void testChunkEncodedRequestWithTrailers()
+ public void testChunkEncodedRequestWithTrailer()
throws Exception
{
String chunk1 = "test";
@@ -1284,8 +1285,80 @@
HTTPEncoding.CR + HTTPEncoding.LF +
"0" + HTTPEncoding.CR + HTTPEncoding.LF +
"Content-Type: text/html"
- + HTTPEncoding.CR + HTTPEncoding.LF;
+ + HTTPEncoding.CR + HTTPEncoding.LF +
+ "" + HTTPEncoding.CR + HTTPEncoding.LF;
+
+ handler.newMessage();
+ handler.foundStartLineFirstField( NioUtil.toByteBuffer( "GET" ) );
+ handler.foundStartLineSecondField( NioUtil.toByteBuffer( "/" ) );
+ handler.foundStartLineThirdField( NioUtil.toByteBuffer( "HTTP/1.1" ) );
+ handler.foundHeaderName( NioUtil.toByteBuffer( "Host" ) );
+ handler.foundHeaderValue( NioUtil.toByteBuffer( "localhost" ) );
+ handler.foundHeaderName( NioUtil.toByteBuffer( "Transfer-encoding" ) );
+ handler.foundHeaderValue( NioUtil.toByteBuffer( "chunked" ) );
+ handler.foundHeaderName( NioUtil.toByteBuffer( "Trailer" ) );
+ handler.foundHeaderValue( NioUtil.toByteBuffer( "Content-Type" ) );
+ handler.getBodyType();
+ handlerControl.setReturnValue( HTTPParser.BODY_TYPE_CHUNKING );
+ handler.foundBody( NioUtil.toByteBuffer( chunk1 ) );
+ handler.foundBody( NioUtil.toByteBuffer( chunk2 ) );
+ handler.foundBody( NioUtil.toByteBuffer( chunk3 ) );
+ handler.hasTrailers();
+ handlerControl.setReturnValue( true );
+ handler.getTrailerNames();
+ handlerControl.setReturnValue(
+ new String[]
+ {
+ "Content-Type"
+ }
+ );
+ handler.foundTrailerName( NioUtil.toByteBuffer( "Content-Type" ) );
+ handler.foundTrailerValue( NioUtil.toByteBuffer( "text/html" ) );
+ handler.endMessage();
+
+ handlerControl.replay();
+ errorHandlerControl.replay();
+
+ doParse( request );
+ errorHandlerControl.verify();
+ handlerControl.verify();
+ }
+
+ public void testChunkEncodedRequestWithMissingTrailerThrowsException()
+ throws Exception
+ {
+ String chunk1 = "test";
+ String chunk2 = "test" + HTTPEncoding.CR + HTTPEncoding.LF +
+ HTTPEncoding.CR + HTTPEncoding.LF;
+ String chunk3 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
+
+ String request =
+ "GET / HTTP/1.1" + HTTPEncoding.CR + HTTPEncoding.LF +
+ "Host: localhost" + HTTPEncoding.CR + HTTPEncoding.LF +
+ "Transfer-encoding: chunked" +
+ HTTPEncoding.CR + HTTPEncoding.LF +
+ "Trailer: Content-Type" +
+ HTTPEncoding.CR + HTTPEncoding.LF +
+ HTTPEncoding.CR + HTTPEncoding.LF +
+ Integer.toHexString( chunk1.length() ) +
+ HTTPEncoding.CR + HTTPEncoding.LF +
+ chunk1 +
+ HTTPEncoding.CR + HTTPEncoding.LF +
+ Integer.toHexString( chunk2.length() ) +
+ HTTPEncoding.CR + HTTPEncoding.LF +
+ chunk2 +
+ HTTPEncoding.CR + HTTPEncoding.LF +
+ Integer.toHexString( chunk3.length() ) +
+ HTTPEncoding.CR + HTTPEncoding.LF +
+ chunk3 +
+ HTTPEncoding.CR + HTTPEncoding.LF +
+ "0" + HTTPEncoding.CR + HTTPEncoding.LF +
+ "" + HTTPEncoding.CR + HTTPEncoding.LF;
+
handler.newMessage();
handler.foundStartLineFirstField( NioUtil.toByteBuffer( "GET" ) );
handler.foundStartLineSecondField( NioUtil.toByteBuffer( "/" ) );
@@ -1310,8 +1383,103 @@
"Content-Type"
}
);
+
+ final HTTPException ex = new HTTPException(
+ HTTPEncoding.STATUS_400_Bad_Request,
+ "Missing trailer 'Content-Type'!" );
+ errorHandler.exceptionOccurred( ex );
+ errorHandlerControl.setThrowable( ex );
+
+ handlerControl.replay();
+ errorHandlerControl.replay();
+
+ try
+ {
+ doParse( request );
+ fail( "Expected an exception!" );
+ }
+ catch( HTTPException th ) { assertEquals( ex, th ); }
+
+
+ errorHandlerControl.verify();
+ handlerControl.verify();
+ }
+
+ public void testChunkEncodedRequestWithMultilineTrailer()
+ throws Exception
+ {
+ String chunk1 = "test";
+ String chunk2 = "test" + HTTPEncoding.CR + HTTPEncoding.LF +
+ HTTPEncoding.CR + HTTPEncoding.LF;
+ String chunk3 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
+
+ String request =
+ "GET / HTTP/1.1" + HTTPEncoding.CR + HTTPEncoding.LF +
+ "Host: localhost" + HTTPEncoding.CR + HTTPEncoding.LF +
+ "Transfer-encoding: chunked" +
+ HTTPEncoding.CR + HTTPEncoding.LF +
+ "Trailer: Content-Type" +
+ HTTPEncoding.CR + HTTPEncoding.LF +
+ HTTPEncoding.CR + HTTPEncoding.LF +
+ Integer.toHexString( chunk1.length() ) +
+ HTTPEncoding.CR + HTTPEncoding.LF +
+ chunk1 +
+ HTTPEncoding.CR + HTTPEncoding.LF +
+ Integer.toHexString( chunk2.length() ) +
+ HTTPEncoding.CR + HTTPEncoding.LF +
+ chunk2 +
+ HTTPEncoding.CR + HTTPEncoding.LF +
+ Integer.toHexString( chunk3.length() ) +
+ HTTPEncoding.CR + HTTPEncoding.LF +
+ chunk3 +
+ HTTPEncoding.CR + HTTPEncoding.LF +
+ "0" + HTTPEncoding.CR + HTTPEncoding.LF +
+ "Content-Type: text/html"
+ + HTTPEncoding.CR + HTTPEncoding.LF +
+ "Extension-Trailer: this is a"
+ + HTTPEncoding.CR + HTTPEncoding.LF +
+ " multiline extension"
+ + HTTPEncoding.CR + HTTPEncoding.LF +
+ " trailer!" +
+ HTTPEncoding.CR + HTTPEncoding.LF +
+ "" + HTTPEncoding.CR + HTTPEncoding.LF;
+
+ handler.newMessage();
+ handler.foundStartLineFirstField( NioUtil.toByteBuffer( "GET" ) );
+ handler.foundStartLineSecondField( NioUtil.toByteBuffer( "/" ) );
+ handler.foundStartLineThirdField( NioUtil.toByteBuffer( "HTTP/1.1" ) );
+ handler.foundHeaderName( NioUtil.toByteBuffer( "Host" ) );
+ handler.foundHeaderValue( NioUtil.toByteBuffer( "localhost" ) );
+ handler.foundHeaderName( NioUtil.toByteBuffer( "Transfer-encoding" ) );
+ handler.foundHeaderValue( NioUtil.toByteBuffer( "chunked" ) );
+ handler.foundHeaderName( NioUtil.toByteBuffer( "Trailer" ) );
+ handler.foundHeaderValue( NioUtil.toByteBuffer( "Content-Type" ) );
+ handler.getBodyType();
+ handlerControl.setReturnValue( HTTPParser.BODY_TYPE_CHUNKING );
+ handler.foundBody( NioUtil.toByteBuffer( chunk1 ) );
+ handler.foundBody( NioUtil.toByteBuffer( chunk2 ) );
+ handler.foundBody( NioUtil.toByteBuffer( chunk3 ) );
+ handler.hasTrailers();
+ handlerControl.setReturnValue( true );
+ handler.getTrailerNames();
+ handlerControl.setReturnValue(
+ new String[]
+ {
+ "Content-Type",
+ "Extension-Trailer"
+ }
+ );
handler.foundTrailerName( NioUtil.toByteBuffer( "Content-Type" ) );
handler.foundTrailerValue( NioUtil.toByteBuffer( "text/html" ) );
+ handler.foundTrailerName( NioUtil.toByteBuffer( "Extension-Trailer" ) );
+ handler.foundTrailerValue( NioUtil.toByteBuffer( "this is a"
+ + HTTPEncoding.CR + HTTPEncoding.LF +
+ " multiline extension"
+ + HTTPEncoding.CR + HTTPEncoding.LF +
+ " trailer!" ) );
handler.endMessage();
handlerControl.replay();
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click