tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cos...@locus.apache.org
Subject cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/util/http Cookies.java ServerCookie.java
Date Fri, 01 Dec 2000 21:39:23 GMT
costin      00/12/01 13:39:22

  Modified:    src/share/org/apache/tomcat/util/http Cookies.java
                        ServerCookie.java
  Removed:     src/share/org/apache/tomcat/helper CookieTools.java
  Log:
  - sync another fix from 3.2 ( thanks Paul Frieden ) ( I did a small change
  to avoid creating new dates and formatting when maxAge==0 )
  
  - added few more comments on Cookie
  
  Submitted by: Paul Frieden <pfrieden@dChain.com>
  
  Revision  Changes    Path
  1.5       +24 -6     jakarta-tomcat/src/share/org/apache/tomcat/util/http/Cookies.java
  
  Index: Cookies.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/http/Cookies.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Cookies.java	2000/12/01 08:19:17	1.4
  +++ Cookies.java	2000/12/01 21:39:21	1.5
  @@ -71,7 +71,9 @@
   /**
    * A collection of cookies - reusable and tuned for server side performance.
    * Based on RFC2965 ( and 2109 )
  - * 
  + *
  + * This class is not synchronized.
  + *
    * @author Costin Manolache
    */
   public final class Cookies { // extends MultiMap {
  @@ -88,6 +90,8 @@
        *  Construct a new cookie collection, that will extract
        *  the information from headers.
        *
  +     * @param headers Cookies are lazy-evaluated and will extract the
  +     *     information from the provided headers.
        */
       public Cookies(MimeHeaders headers) {
   	this.headers=headers;
  @@ -102,6 +106,8 @@
   	unprocessed=true;
       }
   
  +    // -------------------- Indexed access --------------------
  +    
       public ServerCookie getCookie( int idx ) {
   	if( unprocessed ) {
   	    getCookieCount(); // will also update the cookies
  @@ -117,6 +123,12 @@
   	return cookieCount;
       }
   
  +    // -------------------- Adding cookies --------------------
  +
  +    /** Register a new, unitialized cookie. Cookies are recycled, and
  +     *  most of the time an existing ServerCookie object is returned.
  +     *  The caller can set the name/value and attributes for the cookie
  +     */
       public ServerCookie addCookie() {
   	if( cookieCount >= scookies.length  ) {
   	    ServerCookie scookiesTmp[]=new ServerCookie[2*cookieCount];
  @@ -134,10 +146,9 @@
       }
   
   
  -    // -------------------- Static methods ( used to be CookieTools )
  +    // code from CookieTools 
   
  -    /** Process all Cookie headers of a request, setting them
  -     *  in a cookie vector
  +    /** Add all Cookie found in the headers of a request.
        */
       public  void processCookies( MimeHeaders headers ) {
   	if( headers==null )
  @@ -155,18 +166,21 @@
   
   	    // Uncomment to test the new parsing code
   	    if( cookieValue.getType() == MessageBytes.T_BYTES ) {
  -		if( dbg>-1 ) log( "Parsing b[]: " + cookieValue.toString());
  +		if( dbg>0 ) log( "Parsing b[]: " + cookieValue.toString());
   		processCookieHeader( cookieValue.getBytes(),
   				     cookieValue.getOffset(),
   				     cookieValue.getLength());
   	    } else {
  -		if( dbg>-1 ) log( "Parsing S: " + cookieValue.toString());
  +		if( dbg>0 ) log( "Parsing S: " + cookieValue.toString());
   		processCookieHeader( cookieValue.toString() );
   	    }
   	    pos++;// search from the next position
   	}
       }
   
  +    /** Process a byte[] header - allowing fast processing of the
  +     *  raw data
  +     */
       void processCookieHeader(  byte bytes[], int off, int len )
       {
   	if( len<=0 || bytes==null ) return;
  @@ -414,6 +428,8 @@
   	System.out.println("Cookies: " + s);
       }
   
  +    /*
  +
       public static void main( String args[] ) {
   	test("foo=bar; a=b");
   	test("foo=bar;a=b");
  @@ -448,4 +464,6 @@
   	}
   	    
       }
  +
  +    */
   }
  
  
  
  1.5       +14 -6     jakarta-tomcat/src/share/org/apache/tomcat/util/http/ServerCookie.java
  
  Index: ServerCookie.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/http/ServerCookie.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ServerCookie.java	2000/12/01 08:19:17	1.4
  +++ ServerCookie.java	2000/12/01 21:39:22	1.5
  @@ -239,13 +239,16 @@
   	return buf.toString();
       }
   
  +    private static final String ancientDate=DateTool.oldCookieFormat
  +	.format(new Date(10000));
  +    
       /** Return the header value used to set this cookie
        */
       public void getCookieHeaderValue(StringBuffer buf) {
   	ServerCookie cookie=this; 
   	
           // this part is the same for all cookies
  -        buf.append(cookie.getName());
  +	buf.append(cookie.getName());
           buf.append("=");
           maybeQuote(version, buf, cookie.getValue().toString());
   
  @@ -261,7 +264,7 @@
   		maybeQuote (version, buf, cookie.getComment().toString());
   	    }
   	}
  -
  +	
   	// add domain information, if present
   
   	if (! cookie.getDomain().isNull()) {
  @@ -276,10 +279,15 @@
   		// interoperatibility (long word )
   		buf.append ("; Expires=");
   		// Wdy, DD-Mon-YY HH:MM:SS GMT ( Expires netscape format )
  -		DateTool.oldCookieFormat.
  -		    format(new Date( System.currentTimeMillis() +
  -				     cookie.getMaxAge() *1000L) ,buf,
  -			   new FieldPosition(0));
  +		// To expire we need to set the time back in future
  +		// ( pfrieden@dChain.com )
  +                if (cookie.getMaxAge() == 0)
  +		    buf.append( ancientDate );
  +		else
  +                    DateTool.oldCookieFormat.format
  +                        (new Date( System.currentTimeMillis() +
  +                                   cookie.getMaxAge() *1000L), buf,
  +                         new FieldPosition(0));
   
   	    } else {
   		buf.append ("; Max-Age=");
  
  
  

Mime
View raw message