remm        02/03/15 21:33:53

  Modified:    coyote/src/java/org/apache/coyote/tomcat4
                        CoyoteResponse.java
  Log:
  - The sendRedirect algorithm seemed inefficient (although it worked). I left the
    old code commented out in case this causes problems.
    Among other things, it will avoid having to have JSSE to redirect to a HTTP
    URL, but is definitely not as strict as the old algorithm when it comes to
    checking if the URL is well-formed.
  
  Revision  Changes    Path
  1.9       +63 -6     
jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat4/CoyoteResponse.java
  
  Index: CoyoteResponse.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat4/CoyoteResponse.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- CoyoteResponse.java       15 Mar 2002 19:07:35 -0000      1.8
  +++ CoyoteResponse.java       16 Mar 2002 05:33:53 -0000      1.9
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat4/CoyoteResponse.java,v
 1.8 2002/03/15 19:07:35 remm Exp $
  - * $Revision: 1.8 $
  - * $Date: 2002/03/15 19:07:35 $
  + * $Header: 
/home/cvs/jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat4/CoyoteResponse.java,v
 1.9 2002/03/16 05:33:53 remm Exp $
  + * $Revision: 1.9 $
  + * $Date: 2002/03/16 05:33:53 $
    *
    * ====================================================================
    *
  @@ -90,6 +90,8 @@
   import javax.servlet.http.HttpSession;
   import javax.servlet.http.HttpUtils;
   
  +import org.apache.tomcat.util.buf.CharChunk;
  +import org.apache.tomcat.util.buf.UEncoder;
   import org.apache.tomcat.util.http.MimeHeaders;
   import org.apache.tomcat.util.http.ServerCookie;
   
  @@ -114,7 +116,7 @@
    *
    * @author Remy Maucherat
    * @author Craig R. McClanahan
  - * @version $Revision: 1.8 $ $Date: 2002/03/15 19:07:35 $
  + * @version $Revision: 1.9 $ $Date: 2002/03/16 05:33:53 $
    */
   
   public class CoyoteResponse
  @@ -127,6 +129,7 @@
       public CoyoteResponse() {
   
           format.setTimeZone(TimeZone.getTimeZone("GMT"));
  +        urlEncoder.addSafeCharacter('/');
   
       }
   
  @@ -283,6 +286,18 @@
       protected boolean usingWriter = false;
   
   
  +    /**
  +     * URL encoder.
  +     */
  +    protected UEncoder urlEncoder = new UEncoder();
  +
  +
  +    /**
  +     * Recyclable buffer to hold the redirect URL.
  +     */
  +    protected CharChunk redirectURLCC = new CharChunk();
  +
  +
       // --------------------------------------------------------- Public Methods
   
   
  @@ -362,7 +377,7 @@
       /**
        * The request with which this response is associated.
        */
  -    protected org.apache.catalina.Request request = null;
  +    protected CoyoteRequest request = null;
   
       /**
        * Return the Request with which this Response is associated.
  @@ -377,7 +392,7 @@
        * @param request The new associated request
        */
       public void setRequest(org.apache.catalina.Request request) {
  -        this.request = request;
  +        this.request = (CoyoteRequest) request;
       }
   
   
  @@ -1265,6 +1280,47 @@
           if (location == null)
               return (location);
   
  +        boolean leadingSlash = location.startsWith("/");
  +
  +        if (leadingSlash 
  +            || (!leadingSlash && (location.indexOf("://") == -1))) {
  +
  +            redirectURLCC.recycle();
  +
  +            String scheme = request.getScheme();
  +            String name = request.getServerName();
  +            int port = request.getServerPort();
  +            String encodedURI = 
  +                urlEncoder.encodeURL(request.getDecodedRequestURI());
  +
  +            try {
  +                redirectURLCC.append(scheme, 0, scheme.length());
  +                redirectURLCC.append("://", 0, 3);
  +                redirectURLCC.append(name, 0, name.length());
  +                if ((scheme.equals("http") && port != 80)
  +                    || (scheme.equals("https") && port != 443)) {
  +                    redirectURLCC.append(':');
  +                    String portS = port + "";
  +                    redirectURLCC.append(portS, 0, portS.length());
  +                }
  +                if (!leadingSlash) {
  +                    redirectURLCC.append(encodedURI, 0, encodedURI.length());
  +                    redirectURLCC.append('/');
  +                }
  +                redirectURLCC.append(location, 0, location.length());
  +            } catch (IOException e) {
  +                throw new IllegalArgumentException(location);
  +            }
  +
  +            return redirectURLCC.toString();
  +
  +        } else {
  +
  +            return (location);
  +
  +        }
  +
  +/*
           // Construct a new absolute URL if possible (cribbed from
           // the DefaultErrorPage servlet)
           URL url = null;
  @@ -1281,6 +1337,7 @@
               }
           }
           return (url.toExternalForm());
  +*/
   
       }
   
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to