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.
|(get-cookie/single name cookies) → (or/c cookie-value? false/c)|
|name : cookie-name?|
|cookies : string?|
|(let ((c (cookie:add-max-age|
|(set-cookie "foo" "bar")|
"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))))|
Imagine your Cookie header looks like this:
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.
|cookie@ : unit?|
|cookie^ : signature|
Includes everything exported by the net/cookie module.