## HTTPClient
Class Cookie

    java.lang.Object
      HTTPClient.Cookie

All Implemented Interfaces:
  Serializable

Direct Known Subclasses:
  Cookie2

public class Cookie
extends Object
implements 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:

- Quoting: only quotes around the expires value are recognized as such; quotes around any other value are treated as part of the value.
- White space: white space around names and values is ignored
- Default path: if no path parameter is given, the path defaults to the path in the request-uri up to, but not including, the last '/'. Note that this is entirely different from what the spec says.
- Commas and other delimiters: Netscape just parses until the next ';'. This means will allow commas etc inside values.

Since:
  V0.3
See Also:
  Serialized Form

Field Summary
`protected String` `domain`
`protected Date` `expires`
`protected String` `name`
`protected String` `path`
`protected boolean` `secure`
`protected String` `value`

Constructor Summary
`protected` `Cookie(RoRequest req)` Use `parse()` to create cookies.
`` `Cookie(String name, String value, String domain, String path, Date expires, boolean secure)` Create a cookie.

Method Summary
`boolean` `discard()`
`boolean` `equals(Object obj)` Two cookies match if the name, path and domain match.
`Date` `expires()`
`String` `getDomain()` Return the domain this cookie is valid in.
`String` `getName()` Return the name of this cookie.
`String` `getPath()` Return the path this cookie is associated with.
`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(String set_cookie, RoRequest req)` Parses the Set-Cookie header into an array of Cookies.
`protected boolean` `sendWith(RoRequest req)`
`protected String` `toExternalForm()`
`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 String name

### value

    protected String value

### expires

    protected Date expires

### domain

    protected String domain

### path

    protected String path

### secure

    protected boolean secure

Constructor Detail

### Cookie

    public Cookie(String name,
                  String value,
                  String domain,
                  String path,
                  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
  `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(String set_cookie,
                                    RoRequest req)
                             throws 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:
    `ProtocolException` - if an error occurs during parsing

### getName

    public String getName()

  Return the name of this cookie.

### getValue

    public String getValue()

  Return the value of this cookie.

### expires

    public 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 String getDomain()

  Return the domain this cookie is valid in.

### getPath

    public 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.

### equals

    public boolean equals(Object obj)

  Two cookies match if the name, path and domain match.

### toExternalForm

    protected String toExternalForm()

  Returns:
    a string suitable for sending in a Cookie header.

### toString

    public String toString()

  Create a string containing all the cookie fields. The format is that used in the Set-Cookie header.