Skip to content
This repository was 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
Aldo Giambelluca (xoen) wants to merge 4 commits intomasterfrom
ag--dont-copy-body
Open

Don't read body, just set the Content-Length header#68
Aldo Giambelluca (xoen) wants to merge 4 commits intomasterfrom
ag--dont-copy-body

Conversation

@xoen
Copy link
Copy Markdown
Contributor

@xoen Aldo Giambelluca (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
Copy link
Copy Markdown
Contributor Author

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.

Comment thread app/proxy.js Outdated
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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

length?

Copy link
Copy Markdown
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
Copy Markdown
Contributor

@r4vi Ravi Kotecha (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
Copy Markdown
Contributor Author

(rebased on top of changes Ravi merged yesterday)

Copy link
Copy Markdown
Contributor

@andyhd Andy Driver (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
Copy Markdown
Contributor Author

Andy Driver (@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
Copy Markdown
Contributor Author

Andy Driver (@andyhd) / Ravi Kotecha (@r4vi) Does this make sense?

Copy link
Copy Markdown
Contributor

@andyhd Andy Driver (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
Copy Markdown
Contributor Author

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
Copy Markdown
Contributor Author

Ravi Kotecha (@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.

3 participants