-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Fix #1824: HEAD request on static files causes app to stop #1825
Conversation
The problem was that for HEAD requests specifically, we implement an explicit Content-Length header (normally we let httpuv figure out the Content-Length based on the content, but for HEAD we don't return any content but still want to include the Content-Length). The Content-Length header was only implemented correctly for string values, not for raw vectors or file-by-path. This change implements the value correctly for all currently valid httpuv content.
@wch, I didn't include code to only unlink if in a temp dir. It's clear from the |
NULL | ||
} | ||
|
||
if (is.na(result)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When would the result
be NA
? The cases I can think of are an NA
string input, and when file.info()
is called on a file that doesn't exist. A comment about this would be helpful so we remember.
R/middleware.R
Outdated
getResponseContentLength <- function(response, deleteOwnedContent) { | ||
force(deleteOwnedContent) | ||
|
||
result <- if (is.character(response$content)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like you're trying to be strict about checking the input, and so it might be good to check that the length is 1.
Other than a couple small comments, it looks good to me. |
The problem was that for HEAD requests specifically, we implement
an explicit Content-Length header (normally we let httpuv figure
out the Content-Length based on the content, but for HEAD we don't
return any content but still want to include the Content-Length).
The Content-Length header was only implemented correctly for string
values, not for raw vectors or file-by-path. This change implements
the value correctly for all currently valid httpuv content.