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

ressource_route: if default file used, content-type incorrect? #19

Open
greg-minshall opened this issue Nov 9, 2020 · 0 comments
Open

Comments

@greg-minshall
Copy link

if the default file is used (because the path ends in '/'), it appears that the file extension isn't set, and the file is returned, but with an incorrect 'content-type' (i assume it is):

bash % wget -v http://127.0.0.1:8080
--2020-11-09 20:22:48--  http://127.0.0.1:8080/
Connecting to 127.0.0.1:8080... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1321 (1.3K) [text/plain]
Saving to: ‘index.html.2’

index.html.2                                    100%[======================================================================================================>]   1.29K  --.-KB/s    in 0s

2020-11-09 20:22:48 (136 MB/s) - ‘index.html.2’ saved [1321/1321]

this patch, which sets the default file earlier in the handler, seems to fix that. (what it breaks, ...?)

diff --git a/R/ressource_route.R b/R/ressource_route.R
index 549d856..02021fe 100644
--- a/R/ressource_route.R
+++ b/R/ressource_route.R
@@ -109,13 +109,13 @@ ressource_route <- function(..., default_file = 'index.html', default_ext = 'htm
   assert_that(has_attr(mappings, 'names'))
   route$add_handler('get', '/*', function(request, response, keys, ...) {
     path <- request$path
+    if (grepl('/$', path)) path <- paste0(path, default_file)
     file_extension <- file_ext(path)
     has_ext <- file_extension != ''
     found <- FALSE
     file <- NA
     enc <- NA
     real_file <- NA
-    if (grepl('/$', path)) path <- paste0(path, default_file)
     for (i in seq_along(mappings)) {
       mount <- names(mappings)[i]
       if (!grepl(paste0('^', mount), path)) next

with this patch, here is how wget runs

bash % wget http://127.0.0.1:8080
--2020-11-09 20:39:15--  http://127.0.0.1:8080/
Connecting to 127.0.0.1:8080... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1321 (1.3K) [text/html]
Saving to: ‘index.html.3’

index.html.3                                    100%[======================================================================================================>]   1.29K  --.-KB/s    in 0s

2020-11-09 20:39:15 (126 MB/s) - ‘index.html.3’ saved [1321/1321]

(this seems to make the browser launched by fiery::Fire$ignite()'s showcase work, at least for me.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant