[Httpunit-commit] CVS: httpunit/src/com/meterware/httpunit HttpUnitOptions.java,1.6,1.7 HttpWebRespo
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2001-07-02 13:05:59
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory usw-pr-cvs1:/tmp/cvs-serv10516/src/com/meterware/httpunit
Modified Files:
HttpUnitOptions.java HttpWebResponse.java WebClient.java
WebResponse.java
Log Message:
Added support for refresh meta tag
Index: HttpUnitOptions.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HttpUnitOptions.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- HttpUnitOptions.java 2001/06/13 16:38:20 1.6
+++ HttpUnitOptions.java 2001/07/02 13:05:56 1.7
@@ -158,6 +158,27 @@
}
+ /**
+ * Returns true if HttpUnit should automatically follow page refresh requests.
+ * By default, this is false, so that programs can verify the redirect page presented
+ * to users before the browser switches to the new page.
+ **/
+ public static boolean getAutoRefresh() {
+ return _autoRefresh;
+ }
+
+
+ /**
+ * Specifies whether HttpUnit should automatically follow page refresh requests.
+ * By default, this is false, so that programs can verify the redirect page presented
+ * to users before the browser switches to the new page. Setting this to true can
+ * cause an infinite loop on pages that refresh themselves.
+ **/
+ public static void setAutoRefresh( boolean autoRefresh ) {
+ _autoRefresh = autoRefresh;
+ }
+
+
//--------------------------------- private members --------------------------------------
@@ -172,6 +193,8 @@
private static boolean _loggingHttpHeaders;
private static boolean _matchesIgnoreCase = true;
+
+ private static boolean _autoRefresh;
private static int _redirectDelay;
Index: HttpWebResponse.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HttpWebResponse.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- HttpWebResponse.java 2001/06/11 21:21:09 1.10
+++ HttpWebResponse.java 2001/07/02 13:05:56 1.11
@@ -152,7 +152,8 @@
}
- private void readMetaTags( byte[] rawMessage ) throws UnsupportedEncodingException {
+ final
+ protected void readMetaTags( byte[] rawMessage ) throws UnsupportedEncodingException {
ByteTagParser parser = new ByteTagParser( rawMessage );
ByteTag tag = parser.getNextTag();
while (tag != null && !tag.getName().equalsIgnoreCase( "body" )) {
@@ -163,9 +164,10 @@
private void processMetaTag( ByteTag tag ) {
- if (tag.getAttribute( "http_equiv" ) != null &&
- tag.getAttribute( "http_equiv" ).equalsIgnoreCase( "content-type" )) {
+ if ("content-type".equalsIgnoreCase( tag.getAttribute( "http_equiv" ) )) {
inferContentType( tag.getAttribute( "content" ) );
+ } else if ("refresh".equalsIgnoreCase( tag.getAttribute( "http_equiv" ) )) {
+ readRefreshRequest( tag.getAttribute( "content" ) );
}
}
@@ -272,6 +274,9 @@
return "";
} else if (_buffer[ _start ] == '"') {
for (_end = _start+1; _end < _buffer.length && _buffer[ _end ] != '"'; _end++);
+ return new String( _buffer, _start+1, _end-_start-1 );
+ } else if (_buffer[ _start ] == '\'') {
+ for (_end = _start+1; _end < _buffer.length && _buffer[ _end ] != '\''; _end++);
return new String( _buffer, _start+1, _end-_start-1 );
} else if (_buffer[ _start ] == '=') {
_end = _start;
Index: WebClient.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebClient.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- WebClient.java 2001/06/06 13:25:04 1.6
+++ WebClient.java 2001/07/02 13:05:56 1.7
@@ -218,7 +218,9 @@
protected void updateClient( WebResponse response ) throws MalformedURLException, IOException, SAXException {
validateHeaders( response );
updateCookies( response );
- if (response.getHeaderField( "Location" ) == null) {
+ if (HttpUnitOptions.getAutoRefresh() && response.getRefreshRequest() != null) {
+ getResponse( response.getRefreshRequest() );
+ } else if (response.getHeaderField( "Location" ) == null) {
updateFrames( response );
} else {
delay( HttpUnitOptions.getRedirectDelay() );
Index: WebResponse.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -r1.36 -r1.37
--- WebResponse.java 2001/06/13 16:38:20 1.36
+++ WebResponse.java 2001/07/02 13:05:56 1.37
@@ -85,6 +85,25 @@
/**
+ * Returns a request to refresh this page, if any. This request will be defined
+ * by a <meta> tag in the header. If no tag exists, will return null.
+ **/
+ public WebRequest getRefreshRequest() {
+ return _refreshRequest;
+ }
+
+
+ /**
+ * Returns the delay before normally following the request to refresh this page, if any.
+ * This request will be defined by a <meta> tag in the header. If no tag exists,
+ * will return zero.
+ **/
+ public int getRefreshDelay() {
+ return _refreshDelay;
+ }
+
+
+ /**
* Returns the response code associated with this response.
**/
abstract
@@ -323,6 +342,19 @@
}
+ final
+ protected void readRefreshRequest( String contentTypeHeader ) {
+ int splitIndex = contentTypeHeader.indexOf( ';' );
+ if (splitIndex < 0) splitIndex = 0;
+ try {
+ _refreshDelay = Integer.parseInt( contentTypeHeader.substring( 0, splitIndex ) );
+ _refreshRequest = new GetMethodWebRequest( contentTypeHeader.substring( splitIndex+1 ) );
+ } catch (NumberFormatException e) {
+ System.out.println( "Unable to interpret refresh tag: \"" + contentTypeHeader + '"' );
+ }
+ }
+
+
//------------------------------------------ package members ------------------------------------------------
@@ -364,6 +396,10 @@
private String _characterSet;
private Hashtable _newCookies;
+
+ private WebRequest _refreshRequest;
+
+ private int _refreshDelay;
// the following variables are essentially final; however, the JDK 1.1 compiler does not handle blank final variables properly with
|