File tree Expand file tree Collapse file tree 3 files changed +26
-4
lines changed Expand file tree Collapse file tree 3 files changed +26
-4
lines changed Original file line number Diff line number Diff line change @@ -65,7 +65,7 @@ Depends:
65
65
methods
66
66
Imports:
67
67
utils,
68
- httpuv (>= 1.3.2 ),
68
+ httpuv (>= 1.3.3 ),
69
69
mime (>= 0.3),
70
70
jsonlite (>= 0.9.16),
71
71
xtable,
Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ shiny 0.12.1.9xxx
26
26
27
27
* All non-base functions are now explicitly namespaced, to pass checks in
28
28
R-devel.
29
+ * Shiny now correctly handles HTTP HEAD requests. (#876)
29
30
30
31
shiny 0.12.1
31
32
--------------------------------------------------------------------------------
Original file line number Diff line number Diff line change @@ -332,6 +332,15 @@ HandlerManager <- R6Class("HandlerManager",
332
332
headers = list (' Content-Type' = ' text/html' )))
333
333
}
334
334
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
+
335
344
response <- handler(req )
336
345
if (is.null(response ))
337
346
response <- httpResponse(404 , content = " <h1>Not Found</h1>" )
@@ -341,9 +350,21 @@ HandlerManager <- R6Class("HandlerManager",
341
350
headers $ ' Content-Type' <- response $ content_type
342
351
343
352
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
+
347
368
} else {
348
369
# Assume it's a Rook-compatible response
349
370
return (response )
You can’t perform that action at this time.
0 commit comments