[Httpunit-commit] CVS: httpunit/src/com/meterware/pseudoserver HttpRequest.java,1.3,1.4 HttpUserAgen
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2003-06-24 22:39:44
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/pseudoserver
In directory sc8-pr-cvs1:/tmp/cvs-serv25279/src/com/meterware/pseudoserver
Modified Files:
HttpRequest.java HttpUserAgentTest.java PseudoServer.java
Log Message:
Add protocol throttling
Index: HttpRequest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/pseudoserver/HttpRequest.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- HttpRequest.java 19 Mar 2003 15:26:06 -0000 1.3
+++ HttpRequest.java 24 Jun 2003 22:39:41 -0000 1.4
@@ -192,9 +192,6 @@
boolean wantsKeepAlive() {
- /**
- return false;
- /**/
if ("Keep-alive".equalsIgnoreCase( getConnectionHeader() )) {
return true;
} else if (_protocol.equals( "HTTP/1.1" )) {
@@ -202,7 +199,6 @@
} else {
return false;
}
- /**/
}
Index: HttpUserAgentTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/pseudoserver/HttpUserAgentTest.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- HttpUserAgentTest.java 17 Jun 2003 23:23:02 -0000 1.10
+++ HttpUserAgentTest.java 24 Jun 2003 22:39:41 -0000 1.11
@@ -100,6 +100,11 @@
}
+ protected PseudoServer getServer() {
+ return _server;
+ }
+
+
protected void setServerDebug( boolean enabled ) {
_server.setDebug( enabled );
}
Index: PseudoServer.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/pseudoserver/PseudoServer.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- PseudoServer.java 19 Mar 2003 16:31:23 -0000 1.9
+++ PseudoServer.java 24 Jun 2003 22:39:41 -0000 1.10
@@ -34,6 +34,8 @@
private ArrayList _classpathDirs = new ArrayList();
+ private String _maxProtocolLevel = "1.1";
+
public PseudoServer() {
Thread t = new Thread() {
@@ -68,6 +70,11 @@
}
+ public void setMaxProtocolLevel( int majorLevel, int minorLevel ) {
+ _maxProtocolLevel = majorLevel + "." + minorLevel;
+ }
+
+
/**
* Returns the port on which this server is listening.
**/
@@ -237,10 +244,10 @@
private boolean respondToRequest( HttpRequest request, HttpResponseStream response ) {
if (_debug) System.out.println( "** Server thread " + hashCode() + " handling request: " + request );
- boolean keepAlive = request.wantsKeepAlive();
+ boolean keepAlive = isKeepAlive( request );
try {
response.restart();
- response.setProtocol( request.getProtocol() );
+ response.setProtocol( getResponseProtocol( request ) );
WebResource resource = getResource( request );
if (resource == null) {
response.setResponse( HttpURLConnection.HTTP_NOT_FOUND, "unable to find " + request.getURI() );
@@ -263,6 +270,16 @@
response.setResponse( HttpURLConnection.HTTP_INTERNAL_ERROR, t.toString() );
}
return keepAlive;
+ }
+
+
+ private boolean isKeepAlive( HttpRequest request ) {
+ return request.wantsKeepAlive() && _maxProtocolLevel.equals( "1.1" );
+ }
+
+
+ private String getResponseProtocol( HttpRequest request ) {
+ return _maxProtocolLevel.equalsIgnoreCase( "1.1" ) ? request.getProtocol() : "HTTP/1.0";
}
|