HTTPClient
Class Cookie

java.lang.Object
  |
  +--HTTPClient.Cookie
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
Cookie2

public class Cookie
extends java.lang.Object
implements java.io.Serializable

This class represents an http cookie as specified in Netscape's cookie spec; however, because not even Netscape follows their own spec, and because very few folks out there actually read specs but instead just look whether Netscape accepts their stuff, the Set-Cookie header field parser actually tries to follow what Netscape has implemented, instead of what the spec says. Additionally, the parser it will also recognize the Max-Age parameter from rfc-2109, as that uses the same header field (Set-Cookie).

Some notes about how Netscape (4.7) parses:

Since:
V0.3
Version:
0.3-3 06/05/2001
Author:
Ronald Tschalär
See Also:
Serialized Form

Field Summary
protected  java.lang.String domain
           
protected  java.util.Date expires
           
protected  java.lang.String name
           
protected  java.lang.String path
           
protected  boolean secure
           
protected  java.lang.String value
           
 
Constructor Summary
protected Cookie(RoRequest req)
          Use parse() to create cookies.
  Cookie(java.lang.String name, java.lang.String value, java.lang.String domain, java.lang.String path, java.util.Date expires, boolean secure)
          Create a cookie.
 
Method Summary
 boolean discard()
           
 boolean equals(java.lang.Object obj)
          Two cookies match if the name, path and domain match.
 java.util.Date expires()
           
 java.lang.String getDomain()
          Return the domain this cookie is valid in.
 java.lang.String getName()
          Return the name of this cookie.
 java.lang.String getPath()
          Return the path this cookie is associated with.
 java.lang.String getValue()
          Return the value of this cookie.
 boolean hasExpired()
           
 int hashCode()
          Hash up name, path and domain into new hash.
 boolean isSecure()
          Return whether this cookie should only be sent over secure connections.
protected static Cookie[] parse(java.lang.String set_cookie, RoRequest req)
          Parses the Set-Cookie header into an array of Cookies.
protected  boolean sendWith(RoRequest req)
           
protected  java.lang.String toExternalForm()
           
 java.lang.String toString()
          Create a string containing all the cookie fields.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

name

protected java.lang.String name

value

protected java.lang.String value

expires

protected java.util.Date expires

domain

protected java.lang.String domain

path

protected java.lang.String path

secure

protected boolean secure
Constructor Detail

Cookie

public Cookie(java.lang.String name,
              java.lang.String value,
              java.lang.String domain,
              java.lang.String path,
              java.util.Date expires,
              boolean secure)
Create a cookie.
Parameters:
name - the cookie name
value - the cookie value
domain - the host this cookie will be sent to
path - the path prefix for which this cookie will be sent
epxires - the Date this cookie expires, null if at end of session
secure - if true this cookie will only be over secure connections
Throws:
NullPointerException - if name, value, domain, or path is null
Since:
V0.3-1

Cookie

protected Cookie(RoRequest req)
Use parse() to create cookies.
See Also:
parse(java.lang.String, HTTPClient.RoRequest)
Method Detail

parse

protected static Cookie[] parse(java.lang.String set_cookie,
                                RoRequest req)
                         throws java.net.ProtocolException
Parses the Set-Cookie header into an array of Cookies.
Parameters:
set_cookie - the Set-Cookie header received from the server
req - the request used
Returns:
an array of Cookies as parsed from the Set-Cookie header
Throws:
java.net.ProtocolException - if an error occurs during parsing

getName

public java.lang.String getName()
Return the name of this cookie.

getValue

public java.lang.String getValue()
Return the value of this cookie.

expires

public java.util.Date expires()
Returns:
the expiry date of this cookie, or null if none set.

discard

public boolean discard()
Returns:
true if the cookie should be discarded at the end of the session; false otherwise

getDomain

public java.lang.String getDomain()
Return the domain this cookie is valid in.

getPath

public java.lang.String getPath()
Return the path this cookie is associated with.

isSecure

public boolean isSecure()
Return whether this cookie should only be sent over secure connections.

hasExpired

public boolean hasExpired()
Returns:
true if this cookie has expired

sendWith

protected boolean sendWith(RoRequest req)
Parameters:
req - the request to be sent
Returns:
true if this cookie should be sent with the request

hashCode

public int hashCode()
Hash up name, path and domain into new hash.
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Two cookies match if the name, path and domain match.
Overrides:
equals in class java.lang.Object

toExternalForm

protected java.lang.String toExternalForm()
Returns:
a string suitable for sending in a Cookie header.

toString

public java.lang.String toString()
Create a string containing all the cookie fields. The format is that used in the Set-Cookie header.
Overrides:
toString in class java.lang.Object


Copyright © GNU, wttools developers Team.