Apache::Cookie
A class for manipulating a request's HTTP cookies. This functionality is only available if mod_ruby is compiled with Generic Apache Request library (libapreq) support. A hash of the cookies associated with a request can be fetched by calling Apache::Request#cookies?.
Superclass
Object
Constants
- DateFormat
-
The
strftime-compatible date format used in the #expires? attribute for absolute expirations.
Class Methods
new( request, [options] )-
Returns a new
Apache::Cookiefor the specified request (an Apache::Request object). The optional options Hash may be used to initialize the cookie's attributes. The following keys are supported::name-
Sets the
namefield to the given value. :value-
Adds the value to the
valuesfield. :expires-
Sets the
expiresfield to the calculated dateStringorTimeobject. See Apache::Cookie#expires? for a listing of format options. The default isnil. :domain-
Sets the
domainfield to the given value. The default isnil. :path-
Sets the
pathfield to the given value. The default path is derived from the requested uri. :secure-
Sets the
securefield totrueorfalse.
Methods
bake- Add the cookie to the output headers of the request to which it belongs.
domaindomain=-
Get/set the
domainattribute of the cookie. From the Netscape spec:When searching the cookie list for valid cookies, a comparison of the (({domain})) attributes of the cookie is made with the Internet domain name of the host from which the URL will be fetched. If there is a tail match, then the cookie will go through path matching to see if it should be sent. "Tail matching" means that (({domain})) attribute is matched against the tail of the fully qualified domain name of the host. A (({domain})) attribute of "acme.com" would match host names "anvil.acme.com" as well as "shipping.crate.acme.com". Only hosts within the specified domain can set a cookie for a domain and domains must have at least two (2) or three (3) periods in them to prevent domains of the form: ".com", ".edu", and "va.us". Any domain that fails within one of the seven special top level domains listed below only require two periods. Any other domain requires at least three. The seven special top level domains are: "COM", "EDU", "NET", "ORG", "GOV", "MIL", and "INT". The default value of (({domain})) is the host name of the server which generated the cookie response. expiresexpires=-
Sets the
expiresfield. The value can be either aTimeobject or aStringin any of the following formats: namename=- Get/set the name associated with the cookie.
pathpath=-
Get/set the cookie's
pathattribute. From the Netscape spec:The (({path})) attribute is used to specify the subset of URLs in a domain for which the cookie is valid. If a cookie has already passed (({domain})) matching, then the pathname component of the URL is compared with the path attribute, and if there is a match, the cookie is considered valid and is sent along with the URL request. The path "/foo" would match "/foobar" and "/foo/bar.html". The path "/" is the most general path. If the (({path})) is not specified, it as assumed to be the same path as the document being described by the header which contains the cookie. secure=-
Set the cookie's
secureflag to the given value. secure?-
Returns
trueif the cookie'ssecureflag is set. to_s-
Returns the cookie as a
String. value-
Get the first value stored in the cookie as a
String. values-
Get all the values stored in the cookie as an
Array. value=-
Set the value of the cookie. If the new value responds to
#each,#eachwill be called, and the result of calling#to_son each iterated value will be added to the cookie's value. If the new value doesn't respond to#each, the result of calling#to_son the value itself is added.For example:
svarcookie = Apache::Cookie::new( req, :name => 'sessionvars' ) svarcookie.value = [ Time::now, req.headers_in['host'] ] svarcookie.bake
Keyword(s):
References:[ClassReferenceManual] [Apache::Request]