| Title: | HTTP Cookies Parser Middleware |
|---|---|
| Description: | A cookie is a piece of data sent from a web server to a web client which helps in overcoming the statelessness constraint of the HTTP protocol. This package provides the tools to work with them in the form of a cookie parser middleware function, meant to be attached to a bigger R web application, and utilities to write, sign and unsign a cookie. For more details see the Mozilla Developer Network (MDN) web documentation in <https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/Cookies>. |
| Authors: | Julio Collazos [aut, cre] (ORCID: <https://orcid.org/0009-0006-5503-0997>), cookie contributors [ctb, cph] (cookie contributors; authors listed in <https://github.com/jshttp/cookie/graphs/contributors>), cookie-parser contributors [ctb, cph] (cookie-parser contributors; authors listed in <https://github.com/expressjs/cookie-parser/graphs/contributors>), cookie-signature contributors [ctb, cph] (cookie-signature contributors; authors listed in <https://github.com/tj/node-cookie-signature/graphs/contributors>), httpuv authors [ctb, cph] (Development of the http_date_string function) |
| Maintainer: | Julio Collazos <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 1.0.0 |
| Built: | 2026-06-12 14:51:41 UTC |
| Source: | https://github.com/cran/cookie |
Creates a middleware function that parses the Cookie HTTP header and
populates req$cookies. When a secret is provided, signed cookies are
verified and exposed on req$signedCookies.
cookieParser(secret = NULL, options = NULL)cookieParser(secret = NULL, options = NULL)
secret |
A character vector or list of strings used to sign and verify cookies. Optional. |
options |
A function used to decode cookie values. Defaults to
|
A middleware function that sets req$cookies,
req$signedCookies, and req$secret, then calls forward().
Serialises a cookie name-value pair into a Set-Cookie header string.
serialise(name, val = NULL, ...)serialise(name, val = NULL, ...)
name |
A string with the cookie name, or a list with |
val |
A string. The cookie value. |
... |
Additional cookie attributes:
|
A Set-Cookie header string.
serialise("session", "abc123") serialise("id", "42", httpOnly = TRUE, secure = TRUE, sameSite = "lax")serialise("session", "abc123") serialise("id", "42", httpOnly = TRUE, secure = TRUE, sameSite = "lax")
Sign the given val with secret.
sign(val, secret)sign(val, secret)
val |
A string. The cookie value to sign. |
secret |
The secret key used to generate the signature. |
A string of the form "<val>.<signature>".
sign("hello", "tobiiscool")sign("hello", "tobiiscool")
Verifies the signature of a signed cookie value and returns the original
value if valid, or FALSE if the signature does not match.
unsign(input, secret)unsign(input, secret)
input |
A string. A signed cookie value produced by |
secret |
The secret key to verify against. |
The original unsigned value if verification succeeds, FALSE
otherwise.
input <- sign("hello", "tobiiscool") unsign(input, "tobiiscool") unsign(input, "luna")input <- sign("hello", "tobiiscool") unsign(input, "tobiiscool") unsign(input, "luna")