Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Don't read body, just set the Content-Length header #68

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

xoen
Copy link
Contributor

@xoen xoen commented May 16, 2019

We used to read the request body to calculate the Content-Length,
we now just copy the velue of the Content-Length header.
The request body is proxied by default, as you'd expect.

Tested locally against a running RStudio container and it seems to
work. I've uploaded a 37MB ISO image and checked the MD5 of the file
uploaded against the checksum of the original file and the file was
uploaded without corruption.

NOTE: This is to simplify the rstudio-proxy logic before moving it
into the other auth-proxy.

Part of ticket: https://trello.com/c/5twZHrb4/215-try-to-replace-custom-rstudio-auth-proxy-with-our-usual-generic-one

@xoen xoen requested review from andyhd and r4vi May 16, 2019 14:40
@xoen
Copy link
Contributor Author

xoen commented May 16, 2019

As said, I've tested this locally (commenting out the authentication logic) and it seems to work but I'd like to try and use this proxy version in front of my RStudio instance and see if it works as expected.

app/proxy.js Outdated
@@ -8,12 +8,12 @@ var proxy = httpProxy.createProxyServer(config.proxy);

proxy.on('proxyReq', function (proxyReq, req, res, options) {
proxyReq.setHeader('Cookie', insert_auth_cookie(req));
proxy_body(req, proxyReq);
set_content_lenght(req, proxyReq);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

length?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, sorry.

Copy link
Contributor

@r4vi r4vi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spelling mistake but otherwise fine, give it a go

We used to read the request body to calculate the `Content-Length`,
we now just copy the velue of the `Content-Length` header.
The request body is proxied by default, as you'd expect.

Tested locally against a running RStudio container and it seems to
work. I've uploaded a 37MB ISO image and checked the MD5 of the file
uploaded against the checksum of the original file and the file was
uploaded without corruption.

**NOTE**: This is to simplify the `rstudio-proxy` logic before moving
into the other `auth-proxy`.

Part of ticket: https://trello.com/c/5twZHrb4/215-try-to-replace-custom-rstudio-auth-proxy-with-our-usual-generic-one
@xoen
Copy link
Contributor Author

xoen commented May 16, 2019

(rebased on top of changes Ravi merged yesterday)

Copy link
Contributor

@andyhd andyhd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great. I'm not sure it really needs to be in a separate function, since the level of abstraction is the same (ie, both the callback and set_content_length() are setting headers on proxyReq), but that's not really a problem.

@xoen
Copy link
Contributor Author

xoen commented May 16, 2019

@andyhd I was actually thinking about that as the function become so simple but I left as function to not have duplication. But I have a better idea, move the proxy.on('proxyReq|proxyReqWs', ... handler from an anonymous function into a normal function. Bear with me.

- both `proxyReq` and `proxyReqWs` were doing the same thing.
  these events are now handled by the same function
- removed a layer of indirection in the logic that set the `Cookie`
  header and using some constants to make what's happening more explicit
- export `auth.secureCookie()` as `auth.secureCookie()`, having different
  names here doesn't add any value and it can be confusing (I was always
  finding it confusing)
@xoen
Copy link
Contributor Author

xoen commented May 16, 2019

@andyhd / @r4vi Does this make sense?

Copy link
Contributor

@andyhd andyhd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, nice

@xoen
Copy link
Contributor Author

xoen commented May 16, 2019

FYI: I've tried to use this proxy in front of my RStudio instance and it seems to work fine (tested upload of 37MB file and also to run the usual Shiny App in the viewer).

@xoen
Copy link
Contributor Author

xoen commented May 16, 2019

@r4vi Moved to camelCase, at least in the file touched by this PR: b9cb9cd

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

Successfully merging this pull request may close these issues.

None yet

3 participants