Skip to content

Commit

Permalink
replace digest with rlang::hash
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasp85 committed Jan 30, 2025
1 parent d3a345b commit ea335f1
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ Imports:
reqres,
stringi,
tools,
digest,
rlang (>= 1.1.0),
cli
RoxygenNote: 7.3.2
Expand Down
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export(route_stack)
export(sizelimit_route)
import(rlang)
importFrom(R6,R6Class)
importFrom(digest,digest)
importFrom(reqres,as.Request)
importFrom(reqres,from_http_date)
importFrom(reqres,is.Request)
Expand Down
11 changes: 7 additions & 4 deletions R/ressource_route.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
#' - `Content-Type` based on the extension of the file (without any encoding
#' extensions)
#' - `Content-Encoding` based on the negotiated file encoding
#' - `ETag` based on [digest::digest()] of the last modified date
#' - `ETag` based on [rlang::hash()] of the last modified date
#' - `Cache-Control` set to `max-age=3600`
#'
#' Furthermore `Content-Length` will be set automatically by `httpuv`
Expand All @@ -79,7 +79,6 @@
#' a file is found and `continue = FALSE`
#'
#' @importFrom tools file_ext file_path_as_absolute file_path_sans_ext
#' @importFrom digest digest
#' @importFrom reqres from_http_date to_http_date
#' @export
#'
Expand Down Expand Up @@ -142,10 +141,14 @@ ressource_route <- function(..., default_file = 'index.html', default_ext = 'htm
m_since <- request$get_header('If-Modified-Since')
m_time <- file.mtime(real_file)
etag <- request$get_header('If-None-Match')
new_tag <- digest(m_time)
new_tag <- hash(m_time)
if ((!is.null(m_since) && from_http_date(m_since) < m_time) ||
(!is.null(etag) && etag == new_tag)) {
response$status_with_text(304L)
if (request$method == "put") {
response$status_with_text(412L)
} else {
response$status_with_text(304L)
}
} else {
response$body <- c(file = file_path_as_absolute(real_file))
response$type <- file_extension
Expand Down
2 changes: 1 addition & 1 deletion man/ressource_route.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ea335f1

Please sign in to comment.