Author: markt
Date: Wed Oct  1 10:18:19 2014
New Revision: 1628670

URL: http://svn.apache.org/r1628670
Log:
Add Cookie generation to the CookieProcessor interface
Re-plumb the current Cookie generation to use the new interface
Provide an initial (and very incomplete) RFC6265 cookie generation 
implementation

Modified:
    tomcat/trunk/java/org/apache/catalina/connector/Response.java
    tomcat/trunk/java/org/apache/tomcat/util/http/CookieProcessor.java
    tomcat/trunk/java/org/apache/tomcat/util/http/LegacyCookieProcessor.java
    tomcat/trunk/java/org/apache/tomcat/util/http/Rfc6265CookieProcessor.java

Modified: tomcat/trunk/java/org/apache/catalina/connector/Response.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/Response.java?rev=1628670&r1=1628669&r2=1628670&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/connector/Response.java (original)
+++ tomcat/trunk/java/org/apache/catalina/connector/Response.java Wed Oct  1 
10:18:19 2014
@@ -51,7 +51,6 @@ import org.apache.tomcat.util.buf.CharCh
 import org.apache.tomcat.util.buf.UEncoder;
 import org.apache.tomcat.util.http.FastHttpDateFormat;
 import org.apache.tomcat.util.http.MimeHeaders;
-import org.apache.tomcat.util.http.SetCookieSupport;
 import org.apache.tomcat.util.http.parser.MediaTypeCache;
 import org.apache.tomcat.util.net.URL;
 import org.apache.tomcat.util.res.StringManager;
@@ -945,17 +944,17 @@ public class Response
     }
 
     public String generateCookieString(final Cookie cookie) {
-        //web application code can receive a IllegalArgumentException
-        //from the appendCookieValue invocation
+        // Web application code can receive a IllegalArgumentException
+        // from the generateHeader() invocation
         if (SecurityUtil.isPackageProtectionEnabled()) {
             return AccessController.doPrivileged(new 
PrivilegedAction<String>() {
                 @Override
                 public String run(){
-                    return SetCookieSupport.generateHeader(cookie);
+                    return 
getContext().getCookieProcessor().generateHeader(cookie);
                 }
             });
         } else {
-            return SetCookieSupport.generateHeader(cookie);
+            return getContext().getCookieProcessor().generateHeader(cookie);
         }
     }
 

Modified: tomcat/trunk/java/org/apache/tomcat/util/http/CookieProcessor.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/http/CookieProcessor.java?rev=1628670&r1=1628669&r2=1628670&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/http/CookieProcessor.java 
(original)
+++ tomcat/trunk/java/org/apache/tomcat/util/http/CookieProcessor.java Wed Oct  
1 10:18:19 2014
@@ -18,6 +18,8 @@ package org.apache.tomcat.util.http;
 
 import java.nio.charset.Charset;
 
+import javax.servlet.http.Cookie;
+
 public interface CookieProcessor {
 
     /**
@@ -26,8 +28,13 @@ public interface CookieProcessor {
     void parseCookieHeader(MimeHeaders headers, ServerCookies serverCookies);
 
     /**
-     * The character set that is to be used to turn the bytes provided in the
-     * cookie header into characters for the cookie value.
+     * Generate the HTTP header value for the given Cookie.
+     */
+    String generateHeader(Cookie cookie);
+
+    /**
+     * The character set that will be used when converting between bytes and
+     * characters when parsing and/or generating HTTP headers for cookies.
      */
     Charset getCharset();
 }

Modified: 
tomcat/trunk/java/org/apache/tomcat/util/http/LegacyCookieProcessor.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/http/LegacyCookieProcessor.java?rev=1628670&r1=1628669&r2=1628670&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/http/LegacyCookieProcessor.java 
(original)
+++ tomcat/trunk/java/org/apache/tomcat/util/http/LegacyCookieProcessor.java 
Wed Oct  1 10:18:19 2014
@@ -185,6 +185,12 @@ public final class LegacyCookieProcessor
     }
 
 
+    @Override
+    public String generateHeader(javax.servlet.http.Cookie cookie) {
+        return SetCookieSupport.generateHeader(cookie);
+    }
+
+
     /**
      * Parses a cookie header after the initial "Cookie:"
      * [WS][$]token[WS]=[WS](token|QV)[;|,]

Modified: 
tomcat/trunk/java/org/apache/tomcat/util/http/Rfc6265CookieProcessor.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/http/Rfc6265CookieProcessor.java?rev=1628670&r1=1628669&r2=1628670&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/http/Rfc6265CookieProcessor.java 
(original)
+++ tomcat/trunk/java/org/apache/tomcat/util/http/Rfc6265CookieProcessor.java 
Wed Oct  1 10:18:19 2014
@@ -68,4 +68,25 @@ public class Rfc6265CookieProcessor impl
             pos = headers.findHeader("Cookie", ++pos);
         }
     }
+
+
+    @Override
+    public String generateHeader(javax.servlet.http.Cookie cookie) {
+
+        StringBuilder header = new StringBuilder();
+        // TODO: Name validation takes place in Cookie and can not be 
configured
+        //       per Context. Moving it to here would allow per Context config
+        //       but delay validation until the header is generated. However,
+        //       the spec requires an IllegalArgumentException on Cookie
+        //       generation.
+        header.append(cookie.getName());
+        header.append('=');
+        // TODO: Value also needs validation that varies depending on the spec
+        //       being used. This is currently delayed until the header is
+        //       generated.
+        header.append(cookie.getValue());
+
+        // TODO add support for the attributes.
+        return header.toString();
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to