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

Be lenient about Connection header contents when Upgrade header is present #153

Merged
merged 2 commits into from
Jun 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ httpuv 1.4.3.9002

* Fixed [#150](https://github.com/rstudio/httpuv/issues/150), [#151](https://github.com/rstudio/httpuv/issues/151): On some platforms, httpuv would fail to install from a zip file because R's `unzip()` function did not preserve the executable permission for `src/libuv/configure`. ([#152](https://github.com/rstudio/httpuv/pull/152))

* Worked around an issue where Shiny apps couldn't be viewed when launched from RStudio Server using Firefox. ([#153](https://github.com/rstudio/httpuv/pull/153))

httpuv 1.4.3
============
Expand Down
13 changes: 11 additions & 2 deletions src/httprequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,11 +414,20 @@ void HttpRequest::_on_body_error(boost::shared_ptr<HttpResponse> pResponse) {
// Message complete
// ============================================================================

bool HttpRequest::isUpgrade() const {
// Normally this should just be _parser.upgrade. But we also want to allow
// Upgrade: WebSocket + Connection: close, in order to work around an issue
// in RStudio Server's http proxying code with Firefox (only):
// https://github.com/rstudio/rstudio/issues/2940
// https://github.com/rstudio/shiny/issues/2064
return _parser.upgrade || _parser.flags & F_UPGRADE;
}

int HttpRequest::_on_message_complete(http_parser* pParser) {
ASSERT_BACKGROUND_THREAD()
trace("HttpRequest::_on_message_complete");

if (pParser->upgrade)
if (isUpgrade())
return 0;

boost::function<void(boost::shared_ptr<HttpResponse>)> schedule_bg_callback(
Expand Down Expand Up @@ -706,7 +715,7 @@ void HttpRequest::_parse_http_data(char* buffer, const ssize_t n) {
// buffer.
_requestBuffer.insert(_requestBuffer.end(), buffer + parsed, buffer + n);

} else if (_parser.upgrade) {
} else if (isUpgrade()) {
char* pData = buffer + parsed;
size_t pDataLen = n - parsed;

Expand Down
4 changes: 3 additions & 1 deletion src/httprequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ class HttpRequest : public WebSocketConnectionCallbacks,
std::string method() const;
std::string url() const;
const RequestHeaders& headers() const;

// Is the request an Upgrade (i.e. WebSocket connection)?
bool isUpgrade() const;

void sendWSFrame(const char* pHeader, size_t headerSize,
const char* pData, size_t dataSize,
const char* pFooter, size_t footerSize);
Expand Down