19 Cookie: HTTP Client Storage
The
net/cookie library provides
utilities for using cookies as specified in RFC 2109 [
RFC2109].
19.1 Functions
Returns #t if v represents a cookie, #f
otherwise.
Returns #t if v represents a valid domain, #f otherwise.
Returns #t if v is a valid cookie name string, #f otherwise.
Returns #t if v is a valid cookie value string, #f otherwise.
Creates a new cookie, with default values for required fields.
Modifies cookie with a comment, and also returns
cookie.
Modifies cookie with a domain, and also returns
cookie. The domain must match a prefix of the
request URI.
Modifies cookie with a maximum age, and also returns
cookie. The seconds argument is number of seconds
that a client should retain the cookie.
Modifies cookie with a path, and also returns
cookie.
Modifies cookie with a security flag, and also returns
cookie.
Modifies cookie with a version, and also returns
cookie. The default is the only known incarnation of HTTP
cookies: 1.
Prints cookie to a string. Empty fields do not appear in the
output except when there is a required default.
Returns a list with all the values (strings) associated with name.
The method used to obtain the "Cookie" header depends on the
web server. It may be an environment variable (CGI), or you may have
to read it from the input port (FastCGI), or maybe it comes in an
initial-request structure, etc. The get-cookie and
get-cookie/single procedure can be used to extract fields
from a "Cookie" field value.
Like
get-cookie, but returns the just first value string
associated to
name, or #f if no association is found.
Raised for errors when handling cookies.
19.2 Examples
19.2.1 Creating a cookie
Produces
"foo=bar; Max-Age=3600; Path=/servlets; Version=1"
To use this output in a “regular” CGI, instead of the last line use:
(display (format "Set-Cookie: ~a" (print-cookie c)))
and to use with the PLT Web Server, use:
19.2.2 Parsing a cookie
Imagine your Cookie header looks like this:
> (define cookies | "test2=2; test3=3; xfcTheme=theme6; xfcTheme=theme2") |
|
Then, to get the values of the xfcTheme cookie, use
If you try to get a cookie that simply is not there:
Note that not having a cookie is normally not an error. Most clients
won’t have a cookie set then first arrive at your site.
19.3 Cookie Unit
19.4 Cookie Signature
Includes everything exported by the net/cookie module.