[Httpunit-commit] CVS: httpunit/test/com/meterware/pseudoserver PseudoServerTest.java,1.11,1.12 Sock
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2003-09-30 00:15:13
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/pseudoserver
In directory sc8-pr-cvs1:/tmp/cvs-serv22169/test/com/meterware/pseudoserver
Modified Files:
PseudoServerTest.java SocketConnection.java
Log Message:
Handle message terminator for chunked encoding
Index: PseudoServerTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/pseudoserver/PseudoServerTest.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- PseudoServerTest.java 17 Sep 2003 01:21:15 -0000 1.11
+++ PseudoServerTest.java 30 Sep 2003 00:15:05 -0000 1.12
@@ -156,6 +156,26 @@
}
+ public void testPseudoServletWithGET() throws Exception {
+ String resourceName = "tellMe";
+ String name = "Charlie";
+ final String prefix = "Hello there, ";
+ String expectedResponse = prefix + name;
+
+ defineResource( resourceName, new PseudoServlet() {
+ public WebResource getGetResponse() {
+ return new WebResource( prefix + getParameter( "name" )[0], "text/plain" );
+ }
+ } );
+
+ SocketConnection conn = new SocketConnection( "localhost", getHostPort() );
+ SocketConnection.SocketResponse response = conn.getResponse( "GET", '/' + resourceName + "?name=" + name );
+ assertEquals( "Response code", 200, response.getResponseCode() );
+ assertEquals( "Content type", "text/plain", response.getHeader( "Content-Type" ) );
+ assertEquals( "Response", expectedResponse, new String( response.getBody() ) );
+ }
+
+
public void testChunkedRequest() throws Exception {
super.defineResource( "/chunkedServlet", new PseudoServlet() {
public WebResource getPostResponse() {
@@ -173,10 +193,41 @@
}
+ // need test: respond with HTTP_BAD_REQUEST if header line is bad
+
+
+ public void testChunkedRequestFollowedByAnother() throws Exception {
+ super.defineResource( "/chunkedServlet", new PseudoServlet() {
+ public WebResource getPostResponse() {
+ return new WebResource( super.getBody(), "text/plain" );
+ }
+ } );
+
+
+ SocketConnection conn = new SocketConnection( "localhost", getHostPort() );
+ conn.startChunkedResponse( "POST", "/chunkedServlet" );
+ conn.sendChunk( "This " );
+ conn.sendChunk( "is " );
+ conn.sendChunk( "chunked.");
+ SocketConnection.SocketResponse response = conn.getResponse();
+ assertEquals( "retrieved body", "This is chunked.", new String( response.getBody() ) );
+
+
+ // Make a second request to duplicate the problem...
+ conn.startChunkedResponse( "POST", "/chunkedServlet" );
+ conn.sendChunk( "This " );
+ conn.sendChunk( "is " );
+ conn.sendChunk( "also " );
+ conn.sendChunk( "chunked.");
+ SocketConnection.SocketResponse response2 = conn.getResponse();
+ assertEquals( "retrieved body", "This is also chunked.", new String( response2.getBody() ) );
+ }
+
+
public void testChunkedResponse() throws Exception {
defineResource( "/chunkedServlet", new PseudoServlet() {
public WebResource getGetResponse() {
- WebResource webResource = new WebResource( "5\r\nSent \r\n3\r\nin \r\n07\r\nchunks.\r\n0\r\n", "text/plain" );
+ WebResource webResource = new WebResource( "5\r\nSent \r\n3\r\nin \r\n07\r\nchunks.\r\n0\r\n\r\n", "text/plain" );
webResource.addHeader( "Transfer-Encoding: chunked" );
return webResource;
}
Index: SocketConnection.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/pseudoserver/SocketConnection.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SocketConnection.java 17 Sep 2003 01:21:15 -0000 1.1
+++ SocketConnection.java 30 Sep 2003 00:15:05 -0000 1.2
@@ -90,7 +90,9 @@
SocketResponse getResponse() throws IOException {
if (!_isChunking) throw new IllegalStateException( "Not chunking a request." );
+ _isChunking = false;
sendHTTPLine( "0" );
+ sendHTTPLine( "" );
return new SocketResponse( _is );
}
@@ -113,12 +115,12 @@
}
- protected void appendMessageHeader( StringBuffer sb ) {
+ void appendMessageHeader( StringBuffer sb ) {
sb.append( _protocol ).append( ' ' ).append( _responseCode ).append( ' ' ).append( _message );
}
- protected void interpretMessageHeader( String messageHeader ) {
+ void interpretMessageHeader( String messageHeader ) {
int s1 = messageHeader.indexOf( ' ' );
int s2 = messageHeader.indexOf( ' ', s1+1 );
|