Version: 4.1.5
2.4.5 Extracting Cookies
(require web-server/http/cookie-parse) |
(struct client-cookie (name value domain path)) |
name : string? |
value : string? |
domain : (or/c false/c valid-domain?) |
path : (or/c false/c string?) |
While server cookies are represented with cookie?s, cookies that come from the client are represented with a client-cookie structure.
(request-cookies req) → (listof client-cookie?) |
req : request? |
Extracts the cookies from req’s headers.
Examples:
(define (start req) |
(define cookies (request-cookies req)) |
(define id-cookie |
(findf (lambda (c) |
(string=? "id" (client-cookie-name c))) |
cookies)) |
(if id-cookie |
(hello (client-cookie-value id-cookie)) |
(redirect-to |
(url->string (request-uri req)) |
see-other |
#:headers |
(list |
(cookie->header (make-cookie "id" "joseph")))))) |
(define (hello who) |
`(html (head (title "Hello!")) |
(body |
(h1 "Hello " |
,who)))) |