commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject cvs commit: jakarta-commons/httpclient/src/test/org/apache/commons/httpclient TestRedirects.java
Date Fri, 14 Jan 2005 19:40:39 GMT
olegk       2005/01/14 11:40:39

  Modified:    httpclient/src/java/org/apache/commons/httpclient
                        HttpMethodDirector.java
               httpclient/src/test/org/apache/commons/httpclient
                        TestRedirects.java
  Added:       httpclient/src/java/org/apache/commons/httpclient
                        CircularRedirectException.java
  Log:
  PR #33021 (ALLOW_CIRCULAR_REDIRECTS has no effect if references include query string)
  
  Contributed by Ilya Kharmatsky <ilyak at mainsoft.com>
  Reviewed by Oleg Kalnichevski, Michael Becke
  
  Revision  Changes    Path
  1.34      +14 -6     jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodDirector.java
  
  Index: HttpMethodDirector.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodDirector.java,v
  retrieving revision 1.33
  retrieving revision 1.34
  diff -u -r1.33 -r1.34
  --- HttpMethodDirector.java	19 Dec 2004 16:21:42 -0000	1.33
  +++ HttpMethodDirector.java	14 Jan 2005 19:40:39 -0000	1.34
  @@ -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;
  
  
  
  1.1                  jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/CircularRedirectException.java
  
  Index: CircularRedirectException.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/CircularRedirectException.java,v
1.1 2005/01/14 19:40:39 olegk Exp $
   * $Revision: 1.1 $
   * $Date: 2005/01/14 19:40:39 $
   *
   * ====================================================================
   *
   *  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
   * <http://www.apache.org/>.
   *
   */
  
  package org.apache.commons.httpclient;
  
  /**
   * Signals a circular redirect
   * 
   * @author <a href="mailto:oleg@ural.ru">Oleg Kalnichevski</a>
   * 
   * @since 3.0
   */
  public class CircularRedirectException extends RedirectException {
  
      /**
       * Creates a new CircularRedirectException with a <tt>null</tt> 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 <tt>Throwable</tt> that caused this exception, or <tt>null</tt>
       * if the cause is unavailable, unknown, or not a <tt>Throwable</tt>
       */
      public CircularRedirectException(String message, Throwable cause) {
          super(message, cause);
      }
  }
  
  
  
  1.9       +13 -13    jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestRedirects.java
  
  Index: TestRedirects.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestRedirects.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- TestRedirects.java	13 Nov 2004 12:21:28 -0000	1.8
  +++ TestRedirects.java	14 Jan 2005 19:40:39 -0000	1.9
  @@ -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();
           }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message