Index: java/org/apache/commons/httpclient/HttpMethodDirector.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodDirector.java,v
retrieving revision 1.33
diff -u -r1.33 HttpMethodDirector.java
--- java/org/apache/commons/httpclient/HttpMethodDirector.java 19 Dec 2004 16:21:42 -0000 1.33
+++ java/org/apache/commons/httpclient/HttpMethodDirector.java 11 Jan 2005 21:38:05 -0000
@@ -1,5 +1,5 @@
/*
- * $Header: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodDirector.java,v 1.33 2004/12/19 16:21:42 olegk Exp $
+ * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodDirector.java,v 1.33 2004/12/19 16:21:42 olegk Exp $
* $Revision: 1.33 $
* $Date: 2004/12/19 16:21:42 $
*
@@ -593,9 +593,18 @@
this.redirectLocations = new HashSet();
}
this.redirectLocations.add(currentUri);
+ try {
+ if(redirectUri.hasQuery()) {
+ redirectUri.setQuery(null);
+ }
+ } catch (URIException e) {
+ // Should never happen
+ return false;
+ }
+
if (this.redirectLocations.contains(redirectUri)) {
- throw new RedirectException("Circular redirect to '" +
- redirectUri + "'");
+ throw new CircularRedirectException("Circular redirect to '" +
+ redirectUri + "'");
}
}
@@ -603,7 +612,6 @@
LOG.debug("Redirecting from '" + currentUri.getEscapedURI()
+ "' to '" + redirectUri.getEscapedURI());
}
-
//And finally invalidate the actual authentication scheme
method.getHostAuthState().invalidate();
return true;
Index: test/org/apache/commons/httpclient/TestRedirects.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestRedirects.java,v
retrieving revision 1.8
diff -u -r1.8 TestRedirects.java
--- test/org/apache/commons/httpclient/TestRedirects.java 13 Nov 2004 12:21:28 -0000 1.8
+++ test/org/apache/commons/httpclient/TestRedirects.java 11 Jan 2005 21:38:09 -0000
@@ -1,5 +1,5 @@
/*
- * $Header: /home/cvspublic/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestRedirects.java,v 1.8 2004/11/13 12:21:28 olegk Exp $
+ * $Header: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestRedirects.java,v 1.8 2004/11/13 12:21:28 olegk Exp $
* $Revision: 1.8 $
* $Date: 2004/11/13 12:21:28 $
* ====================================================================
@@ -113,21 +113,23 @@
private class CircularRedirectService implements HttpService {
+ private int invocations = 0;
+
public CircularRedirectService() {
super();
}
-
+
public boolean process(final SimpleRequest request, final SimpleResponse response)
throws IOException
{
RequestLine reqline = request.getRequestLine();
HttpVersion ver = reqline.getHttpVersion();
- if (reqline.getUri().equals("/circular-oldlocation/")) {
+ if (reqline.getUri().startsWith("/circular-oldlocation")) {
response.setStatusLine(ver, HttpStatus.SC_MOVED_TEMPORARILY);
- response.addHeader(new Header("Location", "/circular-location2/"));
- } else if (reqline.getUri().equals("/circular-location2/")) {
+ response.addHeader(new Header("Location", "/circular-location2?invk=" + (++this.invocations)));
+ } else if (reqline.getUri().startsWith("/circular-location2")) {
response.setStatusLine(ver, HttpStatus.SC_MOVED_TEMPORARILY);
- response.addHeader(new Header("Location", "/circular-oldlocation/"));
+ response.addHeader(new Header("Location", "/circular-oldlocation?invk=" + (++this.invocations)));
} else {
response.setStatusLine(ver, HttpStatus.SC_NOT_FOUND);
}
@@ -348,10 +350,8 @@
try {
this.client.getParams().setBooleanParameter(HttpClientParams.ALLOW_CIRCULAR_REDIRECTS, false);
this.client.executeMethod(httpget);
- fail("RedirectException exception should have been thrown");
- }
- catch (RedirectException e) {
- // expected
+ fail("CircularRedirectException exception should have been thrown");
+ } catch (CircularRedirectException expected) {
} finally {
httpget.releaseConnection();
}
Index: java/org/apache/commons/httpclient/CircularRedirectException.java
===================================================================
RCS file: java/org/apache/commons/httpclient/CircularRedirectException.java
diff -N java/org/apache/commons/httpclient/CircularRedirectException.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ java/org/apache/commons/httpclient/CircularRedirectException.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,67 @@
+/*
+ * $Header$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ *
+ * Copyright 1999-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ *
+ */
+
+package org.apache.commons.httpclient;
+
+/**
+ * Signals a circular redirect
+ *
+ * @author Oleg Kalnichevski
+ *
+ * @since 3.0
+ */
+public class CircularRedirectException extends RedirectException {
+
+ /**
+ * Creates a new CircularRedirectException with a null detail message.
+ */
+ public CircularRedirectException() {
+ super();
+ }
+
+ /**
+ * Creates a new CircularRedirectException with the specified detail message.
+ *
+ * @param message The exception detail message
+ */
+ public CircularRedirectException(String message) {
+ super(message);
+ }
+
+ /**
+ * Creates a new CircularRedirectException with the specified detail message and cause.
+ *
+ * @param message the exception detail message
+ * @param cause the Throwable that caused this exception, or null
+ * if the cause is unavailable, unknown, or not a Throwable
+ */
+ public CircularRedirectException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}