[Httpunit-commit] CVS: httpunit/src/com/meterware/httpunit HttpWebResponse.java,1.16,1.17 WebClient.
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2002-01-28 18:43:28
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit
In directory usw-pr-cvs1:/tmp/cvs-serv28744/src/com/meterware/httpunit
Modified Files:
HttpWebResponse.java WebClient.java
Log Message:
Clean up handling of disabled auto-redirect
Index: HttpWebResponse.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/HttpWebResponse.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- HttpWebResponse.java 2001/11/09 18:35:14 1.16
+++ HttpWebResponse.java 2002/01/28 18:43:25 1.17
@@ -52,7 +52,7 @@
readHeaders( connection );
/** make sure that any IO exception for HTML received page happens here, not later. **/
- if (_responseCode == HttpURLConnection.HTTP_OK || !HttpUnitOptions.getExceptionsThrownOnErrorStatus()) {
+ if (_responseCode < HttpURLConnection.HTTP_BAD_REQUEST || !HttpUnitOptions.getExceptionsThrownOnErrorStatus()) {
defineRawInputStream( new BufferedInputStream( connection.getInputStream() ) );
if (getContentType().startsWith( "text" )) loadResponseText();
}
Index: WebClient.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebClient.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- WebClient.java 2002/01/25 19:09:08 1.16
+++ WebClient.java 2002/01/28 18:43:25 1.17
@@ -219,12 +219,20 @@
validateHeaders( response );
if (HttpUnitOptions.getAutoRefresh() && response.getRefreshRequest() != null) {
getResponse( response.getRefreshRequest() );
- } else if (!HttpUnitOptions.getAutoRedirect() || response.getHeaderField( "Location" ) == null) {
- updateFrames( response );
- } else {
+ } else if (shouldFollowRedirect( response )) {
delay( HttpUnitOptions.getRedirectDelay() );
getResponse( new RedirectWebRequest( response ) );
+ } else {
+ updateFrames( response );
}
+ }
+
+
+ private boolean shouldFollowRedirect( WebResponse response ) {
+ return HttpUnitOptions.getAutoRedirect()
+ && response.getResponseCode() >= HttpURLConnection.HTTP_MOVED_PERM
+ && response.getResponseCode() <= HttpURLConnection.HTTP_MOVED_TEMP
+ && response.getHeaderField( "Location" ) != null;
}
|