-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
|
||
#' Middleware to parse Cookies | ||
#' | ||
#' Adds the cookies as the `cookies` element of the request object. | ||
#' | ||
#' It ignores cookies in an invalid format. It ignores duplicate cookies: | ||
#' if two cookies have the same name, only the first one is included. | ||
#' | ||
#' @return Handler function. | ||
#' | ||
#' @family middleware | ||
#' @export | ||
|
||
mw_cookie_parser <- function() { | ||
function(req, res) { | ||
ch <- req$get_header("Cookie") %||% "" | ||
req$cookies <- parse_cookies(ch) | ||
"next" | ||
} | ||
} | ||
|
||
parse_cookies <- function(x) { | ||
parts <- strsplit(x, ";", fixed = TRUE, useBytes)[[1]] | ||
dict <- structure(list(), names = character()) | ||
lapply(parts, function(ck) { | ||
ck <- trimws(ck) | ||
key <- sub("^([^=]+)=.*$", "\\1", ck) | ||
if (key == ck) return() | ||
if (!is.null(dict[[key]])) return() | ||
value <- sub("^[^=]+=", "", ck) | ||
dict[[key]] <<- value | ||
}) | ||
dict | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.