[Httpunit-commit] CVS: httpunit/src/com/meterware/httpunit DNSListener.java,NONE,1.1 ClientPropertie
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2003-03-19 19:09:02
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory sc8-pr-cvs1:/tmp/cvs-serv20577/src/com/meterware/httpunit
Modified Files:
ClientProperties.java WebConversation.java
Added Files:
DNSListener.java
Log Message:
Add support for DNS override
--- NEW FILE ---
package com.meterware.httpunit;
/**
* A listener for DNS Requests. Users may implement this interface to bypass the normal DNS lookup.
*
* @author <a href="rus...@ht...">Russell Gold</a>
**/
public interface DNSListener {
/**
* Returns the IP address as a string for the specified host name.
**/
String getIpAddress( String hostName );
}
Index: ClientProperties.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/ClientProperties.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ClientProperties.java 16 Mar 2003 17:22:38 -0000 1.5
+++ ClientProperties.java 19 Mar 2003 19:08:58 -0000 1.6
@@ -210,6 +210,22 @@
}
+ /**
+ * Specifies a listener for DNS requests from the client.
+ */
+ public void setDnsListener( DNSListener dnsListener ) {
+ _dnsListener = dnsListener;
+ }
+
+
+ /**
+ * Returns the listener for DNS requests to be used by the client.
+ */
+ DNSListener getDnsListener() {
+ return _dnsListener;
+ }
+
+
static ClientProperties cloneProperties() {
return new ClientProperties( getDefaultProperties() );
}
@@ -228,6 +244,8 @@
private boolean _acceptGzip = true;
private boolean _autoRedirect = true;
private boolean _autoRefresh = false;
+
+ private DNSListener _dnsListener;
private static ClientProperties _defaultProperties = new ClientProperties();
Index: WebConversation.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebConversation.java,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- WebConversation.java 21 Feb 2003 19:28:04 -0000 1.28
+++ WebConversation.java 19 Mar 2003 19:08:58 -0000 1.29
@@ -54,10 +54,20 @@
* Creates a web response object which represents the response to the specified web request.
**/
protected WebResponse newResponse( WebRequest request, String frameName ) throws MalformedURLException, IOException {
- URLConnection connection = openConnection( request.getURL() );
+ URLConnection connection = openConnection( getRequestURL( request ) );
sendHeaders( connection, request.getHeaderDictionary() );
request.completeRequest( connection );
return new HttpWebResponse( this, frameName, request.getURL(), connection, getExceptionsThrownOnErrorStatus() );
+ }
+
+
+ private URL getRequestURL( WebRequest request ) throws MalformedURLException {
+ DNSListener dnsListener = getClientProperties().getDnsListener();
+ if (dnsListener == null) return request.getURL();
+
+ String hostName = request.getURL().getHost();
+ setHeaderField( "Host", hostName + ':' + request.getURL().getPort() );
+ return new URL( request.getURL().getProtocol(), dnsListener.getIpAddress( hostName ), request.getURL().getPort(), request.getURL().getFile() );
}
|