Skip to content

Commit d334aa2

Browse files
committed
Merge branch 'http-head'
2 parents 241a482 + 710e003 commit d334aa2

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ Depends:
6565
methods
6666
Imports:
6767
utils,
68-
httpuv (>= 1.3.2),
68+
httpuv (>= 1.3.3),
6969
mime (>= 0.3),
7070
jsonlite (>= 0.9.16),
7171
xtable,

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ shiny 0.12.1.9xxx
2626

2727
* All non-base functions are now explicitly namespaced, to pass checks in
2828
R-devel.
29+
* Shiny now correctly handles HTTP HEAD requests. (#876)
2930

3031
shiny 0.12.1
3132
--------------------------------------------------------------------------------

R/middleware.R

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,15 @@ HandlerManager <- R6Class("HandlerManager",
332332
headers=list('Content-Type' = 'text/html')))
333333
}
334334

335+
# Catch HEAD requests. For the purposes of handler functions, they
336+
# should be treated like GET. The difference is that they shouldn't
337+
# return a body in the http response.
338+
head_request <- FALSE
339+
if (identical(req$REQUEST_METHOD, "HEAD")) {
340+
head_request <- TRUE
341+
req$REQUEST_METHOD <- "GET"
342+
}
343+
335344
response <- handler(req)
336345
if (is.null(response))
337346
response <- httpResponse(404, content="<h1>Not Found</h1>")
@@ -341,9 +350,21 @@ HandlerManager <- R6Class("HandlerManager",
341350
headers$'Content-Type' <- response$content_type
342351

343352
response <- filter(req, response)
344-
return(list(status=response$status,
345-
body=response$content,
346-
headers=headers))
353+
if (head_request) {
354+
headers$`Content-Length` <- nchar(response$content, type = "bytes")
355+
return(list(
356+
status = response$status,
357+
body = "",
358+
headers = headers
359+
))
360+
} else {
361+
return(list(
362+
status = response$status,
363+
body = response$content,
364+
headers = headers
365+
))
366+
}
367+
347368
} else {
348369
# Assume it's a Rook-compatible response
349370
return(response)

0 commit comments

Comments
 (0)