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

Remove the Date header as httpuv does this automatically now #380

Merged
merged 5 commits into from
Feb 7, 2019
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Imports:
R6 (>= 2.0.0),
stringi (>= 0.3.0),
jsonlite (>= 0.9.16),
httpuv (>= 1.4.5.9000),
httpuv (>= 1.4.5.9002),
crayon
LazyData: TRUE
ByteCompile: TRUE
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ plumber 0.5.0

* Bumped version of httpuv to >= 1.4.5.9000 to address an unexpected segfault (@shapenaji, [#289](https://github.com/trestletech/plumber/issues/289))

* Date response header is now supplied by httpuv and not plumber. Fixes non standard date response header issues when using different locales. (@shrektan, [#319](https://github.com/trestletech/plumber/pull/319), [#380](https://github.com/trestletech/plumber/pull/380))


plumber 0.4.6
Expand Down
23 changes: 0 additions & 23 deletions R/response.R
Original file line number Diff line number Diff line change
@@ -1,25 +1,3 @@
#' HTTP Date String
#'
#' Given a POSIXct object, return a date string in the format required for a
#' HTTP Date header. For example: "Wed, 21 Oct 2015 07:28:00 GMT"
#'
#' @noRd
http_date_string <- function(time) {
weekday_names <- c("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat")
weekday_num <- as.integer(strftime(time, format = "%w", tz = "GMT")) + 1L
weekday_name <- weekday_names[weekday_num]

month_names <- c("Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec")
month_num <- as.integer(strftime(time, format = "%m", tz = "GMT"))
month_name <- month_names[month_num]

strftime(
time,
paste0(weekday_name, ", %d ", month_name, " %Y %H:%M:%S GMT"),
tz = "GMT"
)
}

PlumberResponse <- R6Class(
"PlumberResponse",
Expand All @@ -38,7 +16,6 @@ PlumberResponse <- R6Class(
},
toResponse = function(){
h <- self$headers
h$Date <- http_date_string(Sys.time())

body <- self$body
if (is.null(body)){
Expand Down
16 changes: 0 additions & 16 deletions tests/testthat/test-response.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,3 @@ test_that("can set multiple same-named headers", {
expect_true(test)
expect_true(another)
})

test_that("http_date_string() returns the same result as in Locale C", {
english_time <- function(x) {
old_lc_time <- Sys.getlocale("LC_TIME")
Sys.setlocale("LC_TIME", "C")
on.exit(Sys.setlocale("LC_TIME", old_lc_time), add = TRUE)
format(x, "%a, %d %b %Y %X %Z", tz = "GMT")
}
x <- as.POSIXct("2018-01-01 01:00:00", tz = "Asia/Shanghai")
expect_equal(http_date_string(x), english_time(x))
# multiple values
x_all_months <- sprintf("2018-%02d-03 12:00:00", 1:12)
x_all_weeks <- sprintf("2018-01-%02d 12:00:00", 1:7)
x <- as.POSIXct(c(x_all_months, x_all_weeks), tz = "Asia/Shanghai")
expect_equal(http_date_string(x), english_time(x))
})