[Httpunit-commit] CVS: httpunit/src/com/meterware/httpunit WebClient.java,1.42,1.43
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2002-10-14 12:40:08
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory usw-pr-cvs1:/tmp/cvs-serv25444/src/com/meterware/httpunit
Modified Files:
WebClient.java
Log Message:
Added support for proxy servers
Index: WebClient.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebClient.java,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -r1.42 -r1.43
--- WebClient.java 11 Oct 2002 01:26:22 -0000 1.42
+++ WebClient.java 14 Oct 2002 12:40:05 -0000 1.43
@@ -35,7 +35,7 @@
* session context, computes relative URLs, and generally emulates the browser behavior
* needed to build an automated test of a web site.
*
- * @author Russell Gold
+ * @author <a href="mailto:rus...@ht...">Russell Gold</a>
* @author Jan Ohrstrom
* @author Seth Ladd
* @author Oliver Imbusch
@@ -47,6 +47,7 @@
/** The current main window. **/
private WebWindow _mainWindow = new WebWindow( this );
private ArrayList _openWindows = new ArrayList();
+ private String _authorizationString;
public WebWindow getMainWindow() {
@@ -267,11 +268,43 @@
* Sets a username and password for a basic authentication scheme.
**/
public void setAuthorization( String userName, String password ) {
- setHeaderField( "Authorization", "Basic " + Base64.encode( userName + ':' + password ) );
+ _authorizationString = "Basic " + Base64.encode( userName + ':' + password );
+ setHeaderField( "Authorization", _authorizationString );
}
/**
+ * Specifies a proxy server to use. Note that at present this is global to all web clients in the VM.
+ */
+ public void setProxyServer( String proxyHost, int proxyPort ) {
+ System.setProperty( "proxyHost", proxyHost );
+ System.setProperty( "proxyPost", Integer.toString( proxyPort ) );
+ }
+
+
+ /**
+ * Returns the name of the active proxy server.
+ */
+ public String getProxyHost() {
+ return System.getProperty( "proxyHost" );
+ }
+
+
+ /**
+ * Returns the number of the active proxy port, or 0 is none is specified.
+ */
+ public int getProxyPort() {
+ try {
+ return Integer.parseInt( System.getProperty( "proxyPort" ) );
+ } catch (NumberFormatException e) {
+ return 0;
+ }
+ }
+
+
+
+
+ /**
* Sets the value for a header field to be sent with all requests. If the value set is null,
* removes the header from those to be sent.
**/
@@ -421,7 +454,13 @@
setHeaderField( "User-Agent", getClientProperties().getUserAgent() );
Hashtable result = (Hashtable) _headers.clone();
if (getCookieHeaderField() != null) result.put( "Cookie", getCookieHeaderField() );
+ if (_authorizationString != null) result.put( getAuthorizationHeaderName(), _authorizationString );
return result;
+ }
+
+
+ private String getAuthorizationHeaderName() {
+ return getProxyHost() != null ? "Proxy-Authorization" : "Authorization";
}
|