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-webapp/src/org/apache/commons/httpclient ReadCookieServlet.java
Date Tue, 18 Feb 2003 15:54:31 GMT
olegk       2003/02/18 07:54:30

  Modified:    httpclient/src/java/org/apache/commons/httpclient
                        HttpMethodBase.java
               httpclient/src/java/org/apache/commons/httpclient/cookie
                        CookieSpecBase.java
               httpclient/src/test/org/apache/commons/httpclient
                        TestWebappCookie.java
               httpclient/src/test-webapp/src/org/apache/commons/httpclient
                        ReadCookieServlet.java
  Log:
  Changelog:
  - In non-strict mode each cookie sent with the request is put on a
  separate request header.
  - In strict mode all cookies are crammed into one request header, as
  before
  
  Contributed by Oleg Kalnichevski
  
  Revision  Changes    Path
  1.114     +15 -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.113
  retrieving revision 1.114
  diff -u -r1.113 -r1.114
  --- HttpMethodBase.java	16 Feb 2003 17:56:17 -0000	1.113
  +++ HttpMethodBase.java	18 Feb 2003 15:54:29 -0000	1.114
  @@ -1317,7 +1317,17 @@
           Cookie[] cookies = matcher.match(conn.getHost(), conn.getPort(),
               getPath(), conn.isSecure(), state.getCookies());
           if ((cookies != null) && (cookies.length > 0)) {
  -            setRequestHeader(matcher.formatCookieHeader(cookies));
  +            if (this.isStrictMode()) {
  +                // In strict mode put all cookies on the same header
  +                getRequestHeaderGroup().addHeader(
  +                  matcher.formatCookieHeader(cookies));
  +            } else {
  +                // In non-strict mode put each cookie on a separate header
  +                for (int i = 0; i < cookies.length; i++) {
  +                    getRequestHeaderGroup().addHeader(
  +                      matcher.formatCookieHeader(cookies[i]));
  +                }
  +            }
           }
       }
   
  
  
  
  1.12      +5 -5      jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/cookie/CookieSpecBase.java
  
  Index: CookieSpecBase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/cookie/CookieSpecBase.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- CookieSpecBase.java	30 Jan 2003 05:01:55 -0000	1.11
  +++ CookieSpecBase.java	18 Feb 2003 15:54:30 -0000	1.12
  @@ -375,8 +375,8 @@
                       + paramValue);
               }
           } else {
  -            if (LOG.isWarnEnabled()) {
  -                LOG.warn("Unrecognized cookie attribute: " 
  +            if (LOG.isDebugEnabled()) {
  +                LOG.debug("Unrecognized cookie attribute: " 
                       + attribute.toString());
               }
           }
  
  
  
  1.10      +57 -6     jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestWebappCookie.java
  
  Index: TestWebappCookie.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestWebappCookie.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- TestWebappCookie.java	2 Feb 2003 11:05:20 -0000	1.9
  +++ TestWebappCookie.java	18 Feb 2003 15:54:30 -0000	1.10
  @@ -109,6 +109,7 @@
   
       public void testSetCookieGet() throws Exception {
           HttpClient client = new HttpClient();
  +        client.setStrictMode(true);
           client.getHostConfiguration().setHost(host, port, "http");
           GetMethod method = new GetMethod("/" + context + "/cookie/write");
           method.setQueryString("simple=set");
  @@ -129,6 +130,7 @@
   
       public void testSetCookiePost() throws Exception {
           HttpClient client = new HttpClient();
  +        client.setStrictMode(true);
           client.getHostConfiguration().setHost(host, port, "http");
           PostMethod method = new PostMethod("/" + context + "/cookie/write");
           method.setRequestBody(new NameValuePair[] { new NameValuePair("simple","set") }
);
  @@ -149,6 +151,7 @@
   
       public void testSetCookiePut() throws Exception {
           HttpClient client = new HttpClient();
  +        client.setStrictMode(true);
           client.getHostConfiguration().setHost(host, port, "http");
           PutMethod method = new PutMethod("/" + context + "/cookie/write");
           method.setQueryString("simple=set");
  @@ -169,6 +172,7 @@
   
       public void testSetExpiredCookieGet() throws Exception {
           HttpClient client = new HttpClient();
  +        client.setStrictMode(true);
           client.getHostConfiguration().setHost(host, port, "http");
           GetMethod method = new GetMethod("/" + context + "/cookie/write");
           method.setQueryString("simple=unset");
  @@ -187,6 +191,7 @@
   
       public void testSetExpiredCookiePut() throws Exception {
           HttpClient client = new HttpClient();
  +        client.setStrictMode(true);
           client.getHostConfiguration().setHost(host, port, "http");
           PutMethod method = new PutMethod("/" + context + "/cookie/write");
           method.setQueryString("simple=unset");
  @@ -205,6 +210,7 @@
   
       public void testSetUnsetCookieGet() throws Exception {
           HttpClient client = new HttpClient();
  +        client.setStrictMode(true);
           client.getHostConfiguration().setHost(host, port, "http");
           GetMethod method = new GetMethod("/" + context + "/cookie/write");
           method.setQueryString("simple=set");
  @@ -238,8 +244,9 @@
           assertEquals(0,client.getState().getCookies().length);
       }
   
  -    public void testSetMultiCookieGet() throws Exception {
  +    public void testSetMultiCookieGetStrict() throws Exception {
           HttpClient client = new HttpClient();
  +        client.setStrictMode(true);
           client.getHostConfiguration().setHost(host, port, "http");
           GetMethod method = new GetMethod("/" + context + "/cookie/write");
           method.setQueryString("simple=set&domain=set");
  @@ -261,8 +268,48 @@
           assertEquals("value",((Cookie)(client.getState().getCookies()[1])).getValue());
       }
   
  +
  +    public void testMultiSendCookieGetNonstrict() throws Exception {
  +        HttpClient client = new HttpClient();
  +        client.getHostConfiguration().setHost(host, port, "http");
  +        GetMethod method = new GetMethod("/" + context + "/cookie/write");
  +        method.setQueryString("simple=set&domain=set");
  +        try {
  +            client.executeMethod(method);
  +        } catch (Throwable t) {
  +            t.printStackTrace();
  +            fail("Unable to execute method : " + t.toString());
  +        }
  +        assertEquals(200,method.getStatusCode());
  +        assertTrue(method.getResponseBodyAsString().indexOf("<title>WriteCookieServlet:
GET</title>") >= 0);
  +        assertTrue(method.getResponseBodyAsString().indexOf("Wrote simplecookie.<br>")
>= 0);
  +        assertTrue(method.getResponseBodyAsString().indexOf("Wrote domaincookie.<br>")
>= 0);
  +        assertEquals(2,client.getState().getCookies().length);
  +        assertEquals("simplecookie", ((Cookie)(client.getState().getCookies()[0])).getName());
  +        assertEquals("value",((Cookie)(client.getState().getCookies()[0])).getValue());
  +        assertEquals("domaincookie", ((Cookie)(client.getState().getCookies()[1])).getName());
  +        assertEquals("value",((Cookie)(client.getState().getCookies()[1])).getValue());
  +
  +        GetMethod method2 = new GetMethod("/" + context + "/cookie/read");
  +        try {
  +            client.executeMethod(method2);
  +        } catch (Throwable t) {
  +            t.printStackTrace();
  +            fail("Unable to execute method : " + t.toString());
  +        }
  +        assertEquals(200,method2.getStatusCode());
  +        String s = method2.getResponseBodyAsString();
  +        assertTrue(s, s.indexOf("<title>ReadCookieServlet: GET</title>") >=
0);
  +        assertTrue(s, s.indexOf("<p><tt>Cookie: $Version=\"1\"; simplecookie=\"value\"</tt></p>")
>= 0);
  +        assertTrue(s, s.indexOf("<p><tt>Cookie: $Version=\"1\"; domaincookie=\"value\";
$Domain=\"" + host + "\"</tt></p>") >= 0);
  +        assertTrue(s, s.indexOf("<tt>simplecookie=\"value\"</tt><br>")
>= 0);
  +        assertTrue(s, s.indexOf("<tt>domaincookie=\"value\"</tt><br>")
>= 0);
  +    }
  +
  +
       public void testSetMultiCookiePut() throws Exception {
           HttpClient client = new HttpClient();
  +        client.setStrictMode(true);
           client.getHostConfiguration().setHost(host, port, "http");
           PutMethod method = new PutMethod("/" + context + "/cookie/write");
           method.setQueryString("simple=set&domain=set");
  @@ -286,6 +333,7 @@
   
       public void testSendCookieGet() throws Exception {
           HttpClient client = new HttpClient();
  +        client.setStrictMode(true);
           client.getHostConfiguration().setHost(host, port, "http");
           GetMethod method = new GetMethod("/" + context + "/cookie/write");
           method.setQueryString("simple=set");
  @@ -320,6 +368,7 @@
   
       public void testMultiSendCookieGet() throws Exception {
           HttpClient client = new HttpClient();
  +        client.setStrictMode(true);
           client.getHostConfiguration().setHost(host, port, "http");
           GetMethod method = new GetMethod("/" + context + "/cookie/write");
           method.setQueryString("simple=set&domain=set");
  @@ -358,6 +407,7 @@
   
       public void testDeleteCookieGet() throws Exception {
           HttpClient client = new HttpClient();
  +        client.setStrictMode(true);
           client.getHostConfiguration().setHost(host, port, "http");
   
           {
  @@ -435,6 +485,7 @@
   
       public void testDeleteCookiePut() throws Exception {
           HttpClient client = new HttpClient();
  +        client.setStrictMode(true);
           client.getHostConfiguration().setHost(host, port, "http");
   
           {
  @@ -655,7 +706,7 @@
               }
               assertEquals(200,method.getStatusCode());
               assertTrue(method.getResponseBodyAsString().indexOf("<title>ReadCookieServlet:
GET</title>") >= 0);
  -            assertTrue(method.getResponseBodyAsString(),method.getResponseBodyAsString().indexOf("<p><tt>Cookie:
null</tt></p>") >= 0);
  +            assertTrue(method.getResponseBodyAsString(),method.getResponseBodyAsString().indexOf("<p><tt>Cookie:
") == -1);
               assertTrue(method.getResponseBodyAsString().indexOf("<tt>pathcookie=value</tt><br>")
== -1);
           }
       }
  
  
  
  1.4       +7 -4      jakarta-commons/httpclient/src/test-webapp/src/org/apache/commons/httpclient/ReadCookieServlet.java
  
  Index: ReadCookieServlet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/test-webapp/src/org/apache/commons/httpclient/ReadCookieServlet.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ReadCookieServlet.java	23 Jan 2003 22:48:49 -0000	1.3
  +++ ReadCookieServlet.java	18 Feb 2003 15:54:30 -0000	1.4
  @@ -76,7 +76,10 @@
           out.println("<head><title>ReadCookieServlet: " + request.getMethod()
+ "</title></head>");
           out.println("<body>");
           out.println("<p>This is a response to an HTTP " + request.getMethod() + "
request.</p>");
  -        out.println("<p><tt>Cookie: " + request.getHeader("Cookie") + "</tt></p>");
  +        Enumeration enum = request.getHeaders("Cookie");
  +        while (enum.hasMoreElements()) {
  +            out.println("<p><tt>Cookie: " + (String)enum.nextElement() + "</tt></p>");
  +        }
           Cookie[] cookies = request.getCookies();
           if(null != cookies) {
               for(int i=0;i<cookies.length;i++) {
  
  
  

---------------------------------------------------------------------
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