Version: 4.1.5
2.4.4 Placing Cookies
(require web-server/http/cookie) |
This module provides functions to create cookies and responses that set them.
| |||||||||||||||||||||||||||||||||||||||||||||||||
name : string? | |||||||||||||||||||||||||||||||||||||||||||||||||
value : string? | |||||||||||||||||||||||||||||||||||||||||||||||||
comment : (or/c false/c string?) = #f | |||||||||||||||||||||||||||||||||||||||||||||||||
domain : (or/c false/c valid-domain?) = #f | |||||||||||||||||||||||||||||||||||||||||||||||||
max-age : (or/c false/c exact-nonnegative-integer?) = #f | |||||||||||||||||||||||||||||||||||||||||||||||||
path : (or/c false/c string?) = #f | |||||||||||||||||||||||||||||||||||||||||||||||||
secure? : (or/c false/c boolean?) = #f |
Constructs a cookie with the appropriate fields.
(cookie->header c) → header? |
c : cookie? |
Constructs a header that sets the cookie.
(xexpr-response/cookies cookies xexpr) → response/full? |
cookies : (listof cookie?) |
xexpr : xexpr/c |
Constructs a response using xexpr that sets all the cookies in cookies.
Examples:
(define time-cookie |
(make-cookie "time" (number->string (current-seconds)))) |
(define id-cookie |
(make-cookie "id" "joseph" #:secure? #t)) |
(redirect-to |
"http://localhost/logged-in" |
see-other |
#:headers |
(map cookie->header |
(list time-cookie id-cookie))) |
(send/suspend |
(lambda (k-url) |
(xexpr-response/cookies |
(list time-cookie id-cookie) |
`(html (head (title "Cookie Example")) |
(body (h1 "You're cookie'd!")))))) |
Warning: When using cookies, make sure you follow the advice of the MIT Cookie Eaters, or you will be susceptible to dangerous attacks.