tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From billbar...@apache.org
Subject cvs commit: jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat4 CoyoteResponse.java
Date Fri, 04 Oct 2002 07:03:09 GMT
billbarker    2002/10/04 00:03:09

  Modified:    coyote/src/java/org/apache/coyote/tomcat4
                        CoyoteResponse.java
  Log:
  Use Craig's URL class to from the redirect request.
  
  This gives us normalisation as well as freeing us from unwanted protocols.
  
  Revision  Changes    Path
  1.27      +16 -42    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.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- CoyoteResponse.java	4 Oct 2002 03:36:27 -0000	1.26
  +++ CoyoteResponse.java	4 Oct 2002 07:03:08 -0000	1.27
  @@ -1305,48 +1305,22 @@
           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();
  -
  +        // Construct a new absolute URL if possible (cribbed from
  +        // the DefaultErrorPage servlet)
  +        URL url = null;
  +        try {
  +            url = new URL(location);
  +        } catch (MalformedURLException e1) {
  +            HttpServletRequest hreq =
  +                (HttpServletRequest) request.getRequest();
  +            String requrl = request.getRequestURL().toString();
               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) {
  -                    String relativePath = request.getDecodedRequestURI();
  -                    int pos = relativePath.lastIndexOf('/');
  -                    relativePath = relativePath.substring(0, pos);
  -                    String encodedURI = urlEncoder.encodeURL(relativePath);
  -                    redirectURLCC.append(encodedURI, 0, encodedURI.length());
  -                    redirectURLCC.append('/');
  -                }
  -                redirectURLCC.append(location, 0, location.length());
  -            } catch (IOException e) {
  +                url = new URL(new URL(requrl), location);
  +            } catch (MalformedURLException e2) {
                   throw new IllegalArgumentException(location);
               }
  -
  -            return redirectURLCC.toString();
  -
  -        } else {
  -
  -            return (location);
  -
           }
  -
  +        return (url.toExternalForm());
       }
   
   
  
  
  

--
To unsubscribe, e-mail:   <mailto:tomcat-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-dev-help@jakarta.apache.org>


Mime
View raw message