commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rwaldh...@apache.org
Subject cvs commit: jakarta-commons/httpclient/src/test/org/apache/commons/httpclient TestWebappRedirect.java
Date Tue, 15 Jan 2002 20:53:47 GMT
rwaldhoff    02/01/15 12:53:47

  Modified:    httpclient/src/java/org/apache/commons/httpclient
                        HttpMethodBase.java
               httpclient/src/test-webapp/src/org/apache/commons/httpclient
                        RedirectServlet.java
               httpclient/src/test/org/apache/commons/httpclient
                        TestWebappRedirect.java
  Log:
  fix bug #5870 (http://nagoya.apache.org/bugzilla/show_bug.cgi?id=5870) by assuming same
protocol/host/port for relative URLs in the Location header
  
  (had to change RedirectServlet to use setHeader directly to keep servlet engine from converting
relative URLs for us)
  
  Revision  Changes    Path
  1.24      +17 -5     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.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- HttpMethodBase.java	15 Jan 2002 20:32:15 -0000	1.23
  +++ HttpMethodBase.java	15 Jan 2002 20:53:47 -0000	1.24
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v
1.23 2002/01/15 20:32:15 rwaldhoff Exp $
  - * $Revision: 1.23 $
  - * $Date: 2002/01/15 20:32:15 $
  + * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v
1.24 2002/01/15 20:53:47 rwaldhoff Exp $
  + * $Revision: 1.24 $
  + * $Date: 2002/01/15 20:53:47 $
    * ====================================================================
    *
    * The Apache Software License, Version 1.1
  @@ -109,7 +109,7 @@
    *
    * @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
    * @author Rodney Waldhoff
  - * @version $Revision: 1.23 $ $Date: 2002/01/15 20:32:15 $
  + * @version $Revision: 1.24 $ $Date: 2002/01/15 20:53:47 $
    */
   public abstract class HttpMethodBase implements HttpMethod {
   
  @@ -503,7 +503,19 @@
                       if(location != null) {
                           URL url = null;
                           try {
  -                            url = new URL(location.getValue());
  +                            if(location.getValue().startsWith("/")) {
  +                                if(log.isDebugEnabled()) {
  +                                    log.debug("Following relative Location header \"" +
location + "\".");
  +                                }
  +                                String protocol = connection.isSecure() ? "https" : "http";
  +                                int port = connection.getPort();
  +                                if(-1 == port) {
  +                                    port = connection.isSecure() ? 443 : 80;
  +                                }
  +                                url = new URL(protocol,connection.getHost(),port,location.getValue());
                               
  +                            } else {
  +                                url = new URL(location.getValue());
  +                            }                            
                           } catch(MalformedURLException e) {
                               log.error("Exception while parsing location header \"" + location
+ "\"",e);
                               throw new HttpException(e.toString());
  
  
  
  1.3       +5 -4      jakarta-commons/httpclient/src/test-webapp/src/org/apache/commons/httpclient/RedirectServlet.java
  
  Index: RedirectServlet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/test-webapp/src/org/apache/commons/httpclient/RedirectServlet.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- RedirectServlet.java	4 Oct 2001 17:49:14 -0000	1.2
  +++ RedirectServlet.java	15 Jan 2002 20:53:47 -0000	1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/httpclient/src/test-webapp/src/org/apache/commons/httpclient/RedirectServlet.java,v
1.2 2001/10/04 17:49:14 rwaldhoff Exp $
  - * $Revision: 1.2 $
  - * $Date: 2001/10/04 17:49:14 $
  + * $Header: /home/cvs/jakarta-commons/httpclient/src/test-webapp/src/org/apache/commons/httpclient/RedirectServlet.java,v
1.3 2002/01/15 20:53:47 rwaldhoff Exp $
  + * $Revision: 1.3 $
  + * $Date: 2002/01/15 20:53:47 $
    * ====================================================================
    *
    * The Apache Software License, Version 1.1
  @@ -78,7 +78,8 @@
           if(null == to) {
               to = "/";
           }
  -        response.sendRedirect(to);
  +        response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);
  +        response.setHeader("Location",to);
       }
   }
   
  
  
  
  1.3       +21 -4     jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestWebappRedirect.java
  
  Index: TestWebappRedirect.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestWebappRedirect.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TestWebappRedirect.java	4 Oct 2001 17:49:13 -0000	1.2
  +++ TestWebappRedirect.java	15 Jan 2002 20:53:47 -0000	1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestWebappRedirect.java,v
1.2 2001/10/04 17:49:13 rwaldhoff Exp $
  - * $Revision: 1.2 $
  - * $Date: 2001/10/04 17:49:13 $
  + * $Header: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestWebappRedirect.java,v
1.3 2002/01/15 20:53:47 rwaldhoff Exp $
  + * $Revision: 1.3 $
  + * $Date: 2002/01/15 20:53:47 $
    * ====================================================================
    *
    * The Apache Software License, Version 1.1
  @@ -83,7 +83,7 @@
    * "httpclient.test.webappContext" property.
    *
    * @author Rodney Waldhoff
  - * @version $Id: TestWebappRedirect.java,v 1.2 2001/10/04 17:49:13 rwaldhoff Exp $
  + * @version $Id: TestWebappRedirect.java,v 1.3 2002/01/15 20:53:47 rwaldhoff Exp $
    */
   public class TestWebappRedirect extends TestWebappBase {
   
  @@ -108,6 +108,23 @@
           client.startSession(host, port);
           GetMethod method = new GetMethod("/" + context + "/redirect");
           method.setQueryString("to=" + URLEncoder.encode("http://" + host + ":" + port +
"/" + context + "/params"));
  +        method.setUseDisk(false);
  +        try {
  +            client.executeMethod(method);
  +        } catch (Throwable t) {
  +            t.printStackTrace();
  +            fail("Unable to execute method : " + t.toString());
  +        }
  +        assertEquals(200,method.getStatusCode());
  +        assert(method.getResponseBodyAsString().indexOf("<title>Param Servlet: GET</title>")
>= 0);
  +    }
  +
  +    // see http://nagoya.apache.org/bugzilla/show_bug.cgi?id=5870
  +    public void testRelativeRedirect() throws Exception {
  +        HttpClient client = new HttpClient();
  +        client.startSession(host, port);
  +        GetMethod method = new GetMethod("/" + context + "/redirect");
  +        method.setQueryString("to=" + URLEncoder.encode("/" + context + "/params"));
           method.setUseDisk(false);
           try {
               client.executeMethod(method);
  
  
  

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


Mime
View raw message