WEBrick and Cookies

WEBrick exposes cookies in a simple, easy to use Cookie class that exposes all the properties of RFC 2109 cookies. Both the HTTPRequest and HTTPResponse handily allow you to read and set cookies on requests.

(Cookies are delicious delicacies.)

WEBrick::Cookie

WEBrick::Cookie is a wrapper around a cookie that exposes all the properties of a cookie. To construct a WEBrick cookie, simply call WEBrick::Cookie.new and provide the name and value for the cookie. After instantiating a cookie you can access cookie's properties with the following methods (descriptions from RFC 2109 and the Netscape Cookie specifications):

name
The name of the cookie. The name of the cookie may only be read, not set
value
The value of the cookie. value should be in a printable ASCII encoding.
version
Identifies which cookie specification this cookie conforms to. 0, the default for Netscape Cookies, and 1 for RFC 2109 cookies.
domain
The domain for which the cookie is valid. An explicitly specified domain must always start with a dot.
expires
A Time or String representing when the cookie should expire. Expires must to be in the following format: Wdy, DD-Mon-YYYY HH:MM:SS GMT
max_age
The lifetime of the cookie in seconds from the time the cookie is sent. A zero value means the cookie should be discarded immediately.
comment
Allows an origin server to document its intended use of a cookie. The user can inspect the information to decide whether to initiate or continue a session with this cookie.
path
The subset of URLs to which the cookie applies.
secure
When set to true, the cookie should only be sent back over a secure connection.

Retrieving and Setting Cookies

Cookies are read in by WEBrick::HTTPRequest automatically, and are available as an Array from HTTPRequest#cookies. When creating a WEBrick::HTTPResponse, cookies may be appended to the HTTPResponse#cookies Array.

Cookies will not be automatically copied from the HTTPRequest to the HTTPResponse. You must do this by hand.