[Httpunit-commit] CVS: httpunit/src/com/meterware/pseudoserver HttpRequest.java,1.2,1.3 HttpUserAgen
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2003-03-19 15:26:11
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/pseudoserver
In directory sc8-pr-cvs1:/tmp/cvs-serv12686/src/com/meterware/pseudoserver
Modified Files:
HttpRequest.java HttpUserAgentTest.java PseudoServer.java
WebResource.java
Log Message:
Support persistent connections
Index: HttpRequest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/pseudoserver/HttpRequest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- HttpRequest.java 19 Mar 2003 03:38:06 -0000 1.2
+++ HttpRequest.java 19 Mar 2003 15:26:06 -0000 1.3
@@ -4,12 +4,12 @@
*
* Copyright (c) 2001-2003, Russell Gold
*
-* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
-* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
+* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
+* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
-* The above copyright notice and this permission notice shall be included in all copies or substantial portions
+* The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
@@ -54,7 +54,7 @@
_command = st.nextToken();
_uri = st.nextToken();
_protocol = st.nextToken();
-
+
if (!_command.equals( "GET" ) && !_command.equals( "POST" ) && !_command.equals( "PUT" )) {
throw new UnknownMethodException( _command );
}
@@ -192,14 +192,17 @@
boolean wantsKeepAlive() {
+ /**
return false;
-// if ("Keep-alive".equalsIgnoreCase( getConnectionHeader() )) {
-// return true;
-// } else if (_protocol.equals( "HTTP/1.1" )) {
-// return !"Close".equalsIgnoreCase( getConnectionHeader() );
-// } else {
-// return false;
-// }
+ /**/
+ if ("Keep-alive".equalsIgnoreCase( getConnectionHeader() )) {
+ return true;
+ } else if (_protocol.equals( "HTTP/1.1" )) {
+ return !"Close".equalsIgnoreCase( getConnectionHeader() );
+ } else {
+ return false;
+ }
+ /**/
}
Index: HttpUserAgentTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/pseudoserver/HttpUserAgentTest.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- HttpUserAgentTest.java 7 Mar 2003 05:04:02 -0000 1.8
+++ HttpUserAgentTest.java 19 Mar 2003 15:26:06 -0000 1.9
@@ -100,6 +100,11 @@
}
+ protected void setServerDebug( boolean enabled ) {
+ _server.setDebug( enabled );
+ }
+
+
protected String getHostPath() {
return _hostPath;
}
Index: PseudoServer.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/pseudoserver/PseudoServer.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- PseudoServer.java 19 Mar 2003 03:38:06 -0000 1.7
+++ PseudoServer.java 19 Mar 2003 15:26:06 -0000 1.8
@@ -157,12 +157,19 @@
}
+ public void setDebug( boolean debug ) {
+ _debug = debug;
+ }
+
+
//------------------------------------- private members ---------------------------------------
private Hashtable _resources = new Hashtable();
private boolean _active = true;
+ private boolean _debug;
+
private String asResourceName( String rawName ) {
if (rawName.startsWith( "/" )) {
@@ -210,6 +217,7 @@
socket.setSoTimeout( 1000 );
socket.setTcpNoDelay( true );
+ if (_debug) System.out.println( "** Created server thread: " + hashCode() );
final BufferedInputStream inputStream = new BufferedInputStream( socket.getInputStream() );
final HttpResponseStream outputStream = new HttpResponseStream( socket.getOutputStream() );
@@ -221,12 +229,14 @@
try { Thread.sleep(10); } catch (InterruptedException e) {}
}
}
+ if (_debug) System.out.println( "** Closing server thread: " + hashCode() );
outputStream.close();
socket.close();
}
private boolean respondToRequest( HttpRequest request, HttpResponseStream response ) {
+ if (_debug) System.out.println( "** Server thread " + hashCode() + " handling request: " + request );
boolean keepAlive = request.wantsKeepAlive();
try {
response.restart();
@@ -241,6 +251,7 @@
}
String[] headers = resource.getHeaders();
for (int i = 0; i < headers.length; i++) {
+ if (_debug) System.out.println( "** Server thread " + hashCode() + " sending header: " + headers[i] );
response.addHeader( headers[i] );
}
response.write( resource );
Index: WebResource.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/pseudoserver/WebResource.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- WebResource.java 19 Mar 2003 03:38:06 -0000 1.5
+++ WebResource.java 19 Mar 2003 15:26:06 -0000 1.6
@@ -98,6 +98,7 @@
_stream = stream;
_contentType = contentType;
_responseCode = responseCode;
+ addHeader( "Connection: close" );
}
|