Skip to content

Commit

Permalink
Revert "cookie expires and max-age arguments format (#215)"
Browse files Browse the repository at this point in the history
I needed to merge the 0.4.4 changes before merging this to have a stable
tag. Will un-revert momentarily.

This reverts commit 3313bed.
  • Loading branch information
trestletech committed Dec 4, 2017
1 parent 3313bed commit 88c46b3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
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))
})


0 comments on commit 88c46b3

Please sign in to comment.