Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cookie expires and max-age arguments format #215

Merged
merged 2 commits into from
Dec 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions R/response.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ cookieToStr <- function(name, value, path, expiration=FALSE, http=FALSE, secure=
expy <- now + expiration
expyStr <- format(expy, format="%a, %e %b %Y %T", tz="GMT", usetz=TRUE)

str <- paste0(str, "Expires: ", expyStr, "; ")
str <- paste0(str, "Max-Age: ", expiration, "; ")
str <- paste0(str, "Expires= ", expyStr, "; ")
str <- paste0(str, "Max-Age= ", expiration, "; ")
} else if (inherits(expiration, "POSIXt")){
seconds <- difftime(expiration, Sys.time(), units="secs")
# TODO: DRY
expyStr <- format(expiration, format="%a, %e %b %Y %T", tz="GMT", usetz=TRUE)
str <- paste0(str, "Expires: ", expyStr, "; ")
str <- paste0(str, "Max-Age: ", as.integer(seconds), "; ")
str <- paste0(str, "Expires= ", expyStr, "; ")
str <- paste0(str, "Max-Age= ", as.integer(seconds), "; ")
} # interpret all other values as session cookies.
}

Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-cookies.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ test_that("cookies can convert to string", {
# line above and below.
# When given as a number of seconds
expect_equal(cookieToStr("abc", 123, expiration=expiresSec),
paste0("abc=123; Expires: ", expyStr, "; Max-Age: ", expiresSec))
paste0("abc=123; Expires= ", expyStr, "; Max-Age= ", expiresSec))
# When given as a POSIXct
# difftime is exclusive, so the Max-Age may be off by one on positive time diffs.
expect_equal(cookieToStr("abc", 123, expiration=expires),
paste0("abc=123; Expires: ", expyStr, "; Max-Age: ", expiresSec-1))
paste0("abc=123; Expires= ", expyStr, "; Max-Age= ", expiresSec-1))

# Works with a negative number of seconds
expiresSec <- -10
Expand All @@ -57,10 +57,10 @@ test_that("cookies can convert to string", {
# line above and below.
# When given as a number of seconds
expect_equal(cookieToStr("abc", 123, expiration=expiresSec),
paste0("abc=123; Expires: ", expyStr, "; Max-Age: ", expiresSec))
paste0("abc=123; Expires= ", expyStr, "; Max-Age= ", expiresSec))
# When given as a POSIXct
expect_equal(cookieToStr("abc", 123, expiration=expires),
paste0("abc=123; Expires: ", expyStr, "; Max-Age: ", expiresSec))
paste0("abc=123; Expires= ", expyStr, "; Max-Age= ", expiresSec))
})