Next: Authentication, Previous: Sessions, Up: Top [Contents]
You have to use #:cookies mode while you defining URL rule handler.
(get "/certain-rule" #:cookies mode (lambda (rc) ...))
mode could be:
And the APIs:
(:cookies-set! rc cookie-name key val) (:cookies-ref rc cookie-name key) (:cookies-setattr! rc cookie-name #:expir #f #:domain #f #:path #f #:secure #f #:http-only #f) (:cookies-remove! rc key) ; remove cookie from client (:cookies-update! rc) ; cookies operations won't work unless you update it
NOTE: You don’t have to call :cookies-update! yourself, since it’ll be called automatically by the hook before response.
For example:
(get "/cookie" #:cookies '(names cc) (lambda (rc) (:cookies-set! rc 'cc "sid" "123321") "ok")) (get "/cookie/:expires" #:cookies '(names cc) (lambda (rc) (:cookies-set! rc 'cc "sid" "123321") (:cookies-setattr! rc 'cc #:expir (string->number (params rc "expires"))) "ok"))
Now you may use this command in the console to see the result:
curl --head localhost:3000/cookie # and curl --head localhost:3000/cookie/120