remm        02/03/19 12:34:41

  Modified:    coyote/src/java/org/apache/coyote/tomcat4
                        CoyoteProcessor.java CoyoteRequest.java
  Log:
  - Switch over to the optimized j-t-c/util code for cookie parsing.
  
  Revision  Changes    Path
  1.17      +34 -28    
jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat4/CoyoteProcessor.java
  
  Index: CoyoteProcessor.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat4/CoyoteProcessor.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- CoyoteProcessor.java      16 Mar 2002 05:31:12 -0000      1.16
  +++ CoyoteProcessor.java      19 Mar 2002 20:34:41 -0000      1.17
  @@ -1,6 +1,6 @@
  -/* * $Header: 
/home/cvs/jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat4/CoyoteProcessor.java,v
 1.16 2002/03/16 05:31:12 remm Exp $
  - * $Revision: 1.16 $
  - * $Date: 2002/03/16 05:31:12 $
  +/* * $Header: 
/home/cvs/jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat4/CoyoteProcessor.java,v
 1.17 2002/03/19 20:34:41 remm Exp $
  + * $Revision: 1.17 $
  + * $Date: 2002/03/19 20:34:41 $
    *
    * ====================================================================
    *
  @@ -85,6 +85,8 @@
   
   import org.apache.tomcat.util.buf.ByteChunk;
   import org.apache.tomcat.util.buf.MessageBytes;
  +import org.apache.tomcat.util.http.Cookies;
  +import org.apache.tomcat.util.http.ServerCookie;
   
   import org.apache.coyote.ActionCode;
   import org.apache.coyote.ActionHook;
  @@ -117,7 +119,7 @@
    *
    * @author Craig R. McClanahan
    * @author Remy Maucherat
  - * @version $Revision: 1.16 $ $Date: 2002/03/16 05:31:12 $
  + * @version $Revision: 1.17 $ $Date: 2002/03/19 20:34:41 $
    */
   
   final class CoyoteProcessor
  @@ -415,7 +417,7 @@
           }
   
           parseHost();
  -        parseCookies();
  +        parseCookies(req);
   
       }
   
  @@ -518,33 +520,37 @@
        * but a conversion to Catalina own cookies would then be needed, which 
        * would take away most if not all of the performance benefit.
        */
  -    protected void parseCookies() {
  +    protected void parseCookies(Request req) {
   
  -        Enumeration values = request.getHeaders("cookie");
  -        while (values.hasMoreElements()) {
  -            String value = values.nextElement().toString();
  -            Cookie cookies[] = RequestUtil.parseCookieHeader(value);
  -            for (int i = 0; i < cookies.length; i++) {
  -                if (cookies[i].getName().equals
  -                    (Globals.SESSION_COOKIE_NAME)) {
  -                    // Override anything requested in the URL
  -                    if (!request.isRequestedSessionIdFromCookie()) {
  -                        // Accept only the first session id cookie
  -                        request.setRequestedSessionId(cookies[i].getValue());
  -                        request.setRequestedSessionCookie(true);
  -                        request.setRequestedSessionURL(false);
  -                        if (debug >= 1)
  -                            log(" Requested cookie session id is " +
  -                                ((HttpServletRequest) request.getRequest())
  -                                .getRequestedSessionId());
  -                    }
  +        Cookies serverCookies = req.getCookies();
  +        int count = serverCookies.getCookieCount();
  +        if (count <= 0)
  +            return;
  +
  +        Cookie[] cookies = new Cookie[count];
  +
  +        for (int i = 0; i < count; i++) {
  +            ServerCookie scookie = serverCookies.getCookie(i);
  +            if (scookie.getName().equals(Globals.SESSION_COOKIE_NAME)) {
  +                // Override anything requested in the URL
  +                if (!request.isRequestedSessionIdFromCookie()) {
  +                    // Accept only the first session id cookie
  +                    request.setRequestedSessionId
  +                        (scookie.getValue().toString());
  +                    request.setRequestedSessionCookie(true);
  +                    request.setRequestedSessionURL(false);
  +                    if (debug >= 1)
  +                        log(" Requested cookie session id is " +
  +                            ((HttpServletRequest) request.getRequest())
  +                            .getRequestedSessionId());
                   }
  -                if (debug >= 1)
  -                    log(" Adding cookie " + cookies[i].getName() + "=" +
  -                        cookies[i].getValue());
  -                request.addCookie(cookies[i]);
               }
  +            Cookie cookie = new Cookie(scookie.getName().toString(),
  +                                       scookie.getValue().toString());
  +            cookies[i] = cookie;
           }
  +
  +        request.setCookies(cookies);
   
       }
   
  
  
  
  1.11      +34 -12    
jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat4/CoyoteRequest.java
  
  Index: CoyoteRequest.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat4/CoyoteRequest.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- CoyoteRequest.java        14 Mar 2002 20:52:59 -0000      1.10
  +++ CoyoteRequest.java        19 Mar 2002 20:34:41 -0000      1.11
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat4/CoyoteRequest.java,v
 1.10 2002/03/14 20:52:59 remm Exp $
  - * $Revision: 1.10 $
  - * $Date: 2002/03/14 20:52:59 $
  + * $Header: 
/home/cvs/jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat4/CoyoteRequest.java,v
 1.11 2002/03/19 20:34:41 remm Exp $
  + * $Revision: 1.11 $
  + * $Date: 2002/03/19 20:34:41 $
    *
    * ====================================================================
    *
  @@ -122,7 +122,7 @@
    *
    * @author Remy Maucherat
    * @author Craig R. McClanahan
  - * @version $Revision: 1.10 $ $Date: 2002/03/14 20:52:59 $
  + * @version $Revision: 1.11 $ $Date: 2002/03/19 20:34:41 $
    */
   
   public class CoyoteRequest
  @@ -187,7 +187,7 @@
       /**
        * The set of cookies associated with this Request.
        */
  -    protected ArrayList cookies = new ArrayList();
  +    protected Cookie[] cookies = null;
   
   
       /**
  @@ -388,7 +388,7 @@
   
           attributes.clear();
           notes.clear();
  -        cookies.clear();
  +        cookies = null;
   
           session = null;
           requestedSessionCookie = false;
  @@ -1142,7 +1142,22 @@
        * @param cookie The new cookie
        */
       public void addCookie(Cookie cookie) {
  -        cookies.add(cookie);
  +
  +        // For compatibility only
  +
  +        int size = 0;
  +        if (cookies != null) {
  +            size = cookies.length;
  +        }
  +
  +        Cookie[] newCookies = new Cookie[size + 1];
  +        for (int i = 0; i < size; i++) {
  +            newCookies[i] = cookies[i];
  +        }
  +        newCookies[size] = cookie;
  +
  +        cookies = newCookies;
  +
       }
   
   
  @@ -1185,7 +1200,7 @@
        * Clear the collection of Cookies associated with this Request.
        */
       public void clearCookies() {
  -        cookies.clear();
  +        cookies = null;
       }
   
   
  @@ -1397,10 +1412,17 @@
        */
       public Cookie[] getCookies() {
   
  -        if (cookies.size() < 1)
  -            return (null);
  -        Cookie results[] = new Cookie[cookies.size()];
  -        return ((Cookie[]) cookies.toArray(results));
  +        return cookies;
  +
  +    }
  +
  +
  +    /**
  +     * Set the set of cookies recieved with this Request.
  +     */
  +    public void setCookies(Cookie[] cookies) {
  +
  +        this.cookies = cookies;
   
       }
   
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to