NOTE: This library is deprecated; use the net-cookies package, instead. That package (source on GitHub) implements RFC 6265 [RFC6265] (which supersedes RFC 2109) and supports creating cookies on the server in an idiom more typical of Racket.
cookie : cookie? seconds : exact-nonnegative-integer?
cookie : cookie? version : exact-nonnegative-integer?
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.
name : cookie-name? cookies : string?
(let ([c (cookie:add-max-age (cookie:add-path (set-cookie "foo" "bar") "/servlets") 3600)]) (print-cookie c))
"foo=bar; Max-Age=3600; Path=/servlets; Version=1"
To use this output in a “regular” CGI, instead of the last line use:
and to use with the PLT Web Server, use:
(make-response/full code message (current-seconds) mime (list (make-header #"Set-Cookie" (string->bytes/utf-8 (print-cookie c)))) body)
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
> (get-cookie "xfcTheme" cookies)
> (get-cookie/single "xfcTheme" cookies)
If you try to get a cookie that simply is not there:
> (get-cookie/single "foo" cookies)
> (get-cookie "foo" cookies)
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.
|(require net/cookie-unit)||package: compatibility-lib|
cookie@ : unit?
|(require net/cookie-sig)||package: compatibility-lib|
cookie^ : signature
Includes everything exported by the net/cookie module.