jsdever 2002/11/08 14:25:08
Modified: httpclient/src/java/org/apache/commons/httpclient
HttpMethodBase.java
httpclient/src/test/org/apache/commons/httpclient
TestMethodsRedirectNoHost.java
Log:
Fix HttpUrlException being thrown incorrectly on redirects.
Reported by Danny Burkes.
Revision Changes Path
1.77 +8 -7
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java
Index: HttpMethodBase.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v
retrieving revision 1.76
retrieving revision 1.77
diff -u -r1.76 -r1.77
--- HttpMethodBase.java 31 Oct 2002 07:45:34 -0000 1.76
+++ HttpMethodBase.java 8 Nov 2002 22:25:07 -0000 1.77
@@ -904,7 +904,7 @@
URL currentUrl = null;
try {
- currentUrl = new URL(conn.getProtocol(),
+ currentUrl = new URL(conn.getProtocol().toLowerCase(),
conn.getHost(), conn.getPort(), "");
redirectUrl = new URL(location);
} catch (MalformedURLException e) {
@@ -914,6 +914,7 @@
return false;
} else { //location is incomplete, use current values for defaults
try {
+ log.debug("Redirect URL is not absolute - parsing as relative");
redirectUrl = new URL(currentUrl, location);
} catch (MalformedURLException ex) {
log.warn("Redirected location '" + location
@@ -959,8 +960,8 @@
throws HttpException {
log.trace("enter HttpMethodBase.checkValidRedirect(HttpConnection, URL)");
- String oldProtocol = currentUrl.getProtocol().toLowerCase();
- String newProtocol = redirectUrl.getProtocol().toLowerCase();
+ String oldProtocol = currentUrl.getProtocol();
+ String newProtocol = redirectUrl.getProtocol();
if (! oldProtocol.equals(newProtocol)) {
throw new HttpException("Redirect from protocol " + oldProtocol
+ " to " + newProtocol + " is not supported");
1.2 +17 -4
jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestMethodsRedirectNoHost.java
Index: TestMethodsRedirectNoHost.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestMethodsRedirectNoHost.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestMethodsRedirectNoHost.java 31 Oct 2002 07:45:35 -0000 1.1
+++ TestMethodsRedirectNoHost.java 8 Nov 2002 22:25:08 -0000 1.2
@@ -126,6 +126,19 @@
assertEquals("/newfile", method.getPath());
}
+ public void testRedirectIgnoreCase() throws Exception {
+ addRedirectResponse("HtTP://localhost/newfile");
+ addOkResponse();
+ conn.open();
+
+ HttpMethod method = new SimpleHttpMethod("/oldfile");
+ method.setFollowRedirects(true);
+ method.execute(new HttpState(), conn);
+ Header locationHeader = method.getResponseHeader("Location");
+ assertEquals(200, method.getStatusCode());
+ assertEquals("/newfile", method.getPath());
+
+ }
public void testPostRedirect() throws Exception {
--
To unsubscribe, e-mail: <mailto:commons-dev-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@;jakarta.apache.org>