#325 Cookies never expire (again)

closed
None
5
2008-01-15
2005-08-31
Stevers
No

HTTPUnit is receiving several "expired" cookies from
the server and accepting them into the cookie jar. In
CookieJar.java, findCookies, line 70 has cookieHeader
with 2 (RFC2109 recipe) values:

resellerName=; Expires=Wed, 01-Jan-2003 01:00:00 GMT;Path=/
resellerEMail=; Expires=Wed, 01-Jan-2003 01:00:00
GMT;Path=/

and then sends blank values back to the server with the
next request.

I fixed it by adding these 2 lines in Cookie.java, line 56:

SimpleDateFormat df = (SimpleDateFormat)
DateFormat.getDateInstance();
df.applyPattern( "EEE,dd-MMM-yyyy HH:mm:ss z" );

and farther down

} else if (key.equalsIgnoreCase( "expires" )) {
try {
_expiredTime = df.parse( attributeValue
).getTime();
} catch ( Exception e ) {
e.printStackTrace( System.err );
}

Obviously I don't have a lot of faith in this code yet
(may not be the exact format; df should be a static
global, not created every time into the method) but it
has gotten me past my initial problem.

Discussion

  • Laurent Wozniak

    Laurent Wozniak - 2005-09-05

    Logged In: YES
    user_id=719431

    Same code as the above but made the date format global:

    public class Cookie {

    /**
    * DateFormat to be used to format original Netscape cookies
    */
    private final static DateFormat originalCookieFormat =
    new SimpleDateFormat("EEE,dd-MMM-yyyy HH:mm:ss z",
    Locale.US);

    static {

    originalCookieFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
    }

    ...

    Cookie( String name, String value, Map attributes ) {
    this( name, value );
    for (Iterator iterator =
    attributes.keySet().iterator(); iterator.hasNext();) {
    String key = (String) iterator.next();
    String attributeValue = (String) attributes.get(
    key );
    if (key.equalsIgnoreCase( "path" )) {
    _path = attributeValue;
    } else if (key.equalsIgnoreCase( "domain" )) {
    _domain = attributeValue;
    } else if (key.equalsIgnoreCase( "max-age" )) {
    _expiredTime = System.currentTimeMillis() +
    getAgeInMsec( attributeValue );
    } else if (key.equalsIgnoreCase( "expires" )) {
    _expiredTime = getAgeInMsecFromDate(
    attributeValue );
    }
    }
    }

    private long getAgeInMsecFromDate( String dateValue ) {
    try {
    // SimpleDateFormat isn't thread-safe
    synchronized(originalCookieFormat) {
    return originalCookieFormat.parse( dateValue
    ).getTime();
    }
    } catch (ParseException e) {
    return 0;
    }
    }

    ...

     
  • Garrick Toubassi

    Logged In: YES
    user_id=1081055

    I'm also hitting this problem using httpunit to drive Gmail
    (for filebunker.sourceforge.net). The fix I employed
    successfully was morally equivalent to this one.

     
  • Wolfgang Fahl

    Wolfgang Fahl - 2007-12-31
    • assigned_to: nobody --> wolfgang_fahl
    • status: open --> pending
     
  • SourceForge Robot

    Logged In: YES
    user_id=1312539
    Originator: NO

    This Tracker item was closed automatically by the system. It was
    previously set to a Pending status, and the original submitter
    did not respond within 14 days (the time period specified by
    the administrator of this Tracker).

     
  • SourceForge Robot

    • status: pending --> closed
     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks