Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
keller-mark committed Sep 29, 2023
1 parent a0bcc13 commit 5ab79f3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Imports:
jsonlite,
R6,
plumber,
mime,
future,
httpuv,
stringr,
Expand Down
13 changes: 8 additions & 5 deletions R/content-types.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,16 @@ knownContentTypes <- c(
yaml = "application/yaml"
)

getContentType <- function(ext, defaultType = 'application/octet-stream') {
get_content_type <- function(ext, defaultType = 'application/octet-stream') {
ext <- tolower(ext)

ret <-
knownContentTypes[ext] %|%
mime::mimemap[ext] %|%
defaultType
if(!is.null(knownContentTypes[ext])) {
ret <- knownContentTypes[ext]
} else if(!is.null(mime::mimemap[ext])) {
ret <- mime::mimemap[ext]
} else {
ret <- defaultType
}

ret[[1]]
}
4 changes: 2 additions & 2 deletions R/server.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ VitessceConfigServerFileRoute <- R6::R6Class("VitessceConfigServerFileRoute",
# Adapted from https://github.com/rstudio/plumber/blob/e829af6a94380cb897441c1c56129504afb9564f/R/plumber-static.R#L70C9-L85C12
ext <- tools::file_ext(self$file_path)
info <- file.info(self$file_path)
contentType <- getContentType(ext)
res$headers[["Content-Type"]] <- contentType
content_type <- get_content_type(ext)
res$headers[["Content-Type"]] <- content_type
res$headers[["Content-Length"]] <- info$size
res$headers[["Last-Modified"]] <- http_date_string(info$mtime)
res$body <- NULL # For HEAD request.
Expand Down

0 comments on commit 5ab79f3

Please sign in to comment.