geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickmcgu...@apache.org
Subject svn commit: r628012 - in /geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec: HttpIoHandler.java HttpMessage.java HttpRequestEncoder.java
Date Fri, 15 Feb 2008 11:16:41 GMT
Author: rickmcguire
Date: Fri Feb 15 03:16:31 2008
New Revision: 628012

URL: http://svn.apache.org/viewvc?rev=628012&view=rev
Log:
GERONIMO-3846 cookies are not carried over when requests are redirected


Modified:
    geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpIoHandler.java
    geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpMessage.java
    geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpRequestEncoder.java

Modified: geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpIoHandler.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpIoHandler.java?rev=628012&r1=628011&r2=628012&view=diff
==============================================================================
--- geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpIoHandler.java
(original)
+++ geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpIoHandler.java
Fri Feb 15 03:16:31 2008
@@ -155,6 +155,8 @@
             // we also need to clear out the parameters and the content
             request.clearAllParameters();
             request.clearContent();
+            // make sure to add the cookies from the response
+            request.addCookies(response.getCookies());
 
             //Send the redirect
             client.sendRequest(request);
@@ -195,8 +197,11 @@
                     // cache the session before we return
                     cache.cacheSession(ioSession);
                 }
-                
+
+                // make sure to add the cookies from the response
+                request.addCookies(response.getCookies());
                 request.setAuthCount(authCount);
+                
                 client.sendRequest(request);
 
                 return;

Modified: geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpMessage.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpMessage.java?rev=628012&r1=628011&r2=628012&view=diff
==============================================================================
--- geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpMessage.java (original)
+++ geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpMessage.java Fri
Feb 15 03:16:31 2008
@@ -22,8 +22,11 @@
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.ahc.util.NameValuePair;
 
@@ -48,7 +51,7 @@
     protected List<NameValuePair> headers = new ArrayList<NameValuePair>();
     
     /** The cookies associated with the message. */
-    protected List<Cookie> cookies = new ArrayList<Cookie>();
+    protected Map<String,Cookie> cookies = new HashMap<String,Cookie>();
     
     /** The content type. */
     protected String contentType;
@@ -119,17 +122,43 @@
      * 
      * @return the cookies
      */
-    public List<Cookie> getCookies() {
-        return cookies;
+    public Collection<Cookie> getCookies() {
+        return cookies.values();
     }
 
     /**
-     * Sets the cookies.
+     * Sets the cookies on the message.  Any existing cookies will be completely
+     * discarded.
      * 
      * @param cookies the new cookies
+     * @see #addCookies(Collection)
      */
-    public void setCookies(List<Cookie> cookies) {
-        this.cookies = cookies;
+    public void setCookies(Collection<Cookie> cookies) {
+        if (cookies == null) {
+            throw new IllegalArgumentException("null cookie set was passed in");
+        }
+        
+        Map<String,Cookie> newCookies = new HashMap<String,Cookie>();
+        for (Cookie cookie : cookies) {
+            newCookies.put(cookie.getName(), cookie);
+        }
+        this.cookies = newCookies;
+    }
+    
+    /**
+     * Adds the cookies to the message.  Only the existing cookies with the same
+     * names are replaced by the ones in the argument.
+     * 
+     * @see #setCookies(Collection)
+     */
+    public void addCookies(Collection<Cookie> cookies) {
+        if (cookies == null) {
+            return;
+        }
+        
+        for (Cookie cookie : cookies) {
+            addCookie(cookie);
+        }
     }
 
     /**
@@ -138,7 +167,11 @@
      * @param cookie the cookie
      */
     public void addCookie(Cookie cookie) {
-        this.cookies.add(cookie);
+        if (cookie == null) {
+            return;
+        }
+        
+        this.cookies.put(cookie.getName(), cookie);
     }
 
 

Modified: geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpRequestEncoder.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpRequestEncoder.java?rev=628012&r1=628011&r2=628012&view=diff
==============================================================================
--- geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpRequestEncoder.java
(original)
+++ geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpRequestEncoder.java
Fri Feb 15 03:16:31 2008
@@ -22,6 +22,7 @@
 import java.nio.charset.CharacterCodingException;
 import java.nio.charset.Charset;
 import java.nio.charset.CharsetEncoder;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
@@ -257,7 +258,7 @@
      */
     private void processCookies(HttpRequestMessage msg, ByteBuffer buf, CharsetEncoder encoder)
         throws Exception {
-        List<Cookie> cookies = msg.getCookies();
+        Collection<Cookie> cookies = msg.getCookies();
         if (cookies.size() > 0) {
             buf.putString("Cookie: ", encoder);
             for (Cookie cookie : cookies) {



Mime
View raw message