-
Notifications
You must be signed in to change notification settings - Fork 7
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
Proxy D2L files using python #845
Conversation
4539d1a
to
19b719d
Compare
"""Add headers for 3rd party providers which we access data from.""" | ||
|
||
# Pass our abuse policy in request headers for third-party site admins. | ||
headers["X-Abuse-Policy"] = "https://web.hypothes.is/abuse-policy/" | ||
headers["X-Complaints-To"] = "https://web.hypothes.is/report-abuse/" | ||
|
||
if request and "via.secret.headers" in request.params: |
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.
Adding this here so every request benefits from it (at least the python ones).
def _is_d2l_url(cls, url): | ||
return any(regexp.match(url) for regexp in cls._D2L_URL) | ||
|
||
def _proxy_python_pdf(self, url, route="proxy_python_pdf"): |
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.
Making this method a bit generic instead of copy/paste a similar version.
) | ||
config.add_route("proxy_d2l_pdf", "/d2l/proxied.pdf", factory=QueryURLResource) | ||
config.add_route("proxy_python_pdf", "proxied.pdf", factory=QueryURLResource) |
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.
This last route is a bit extra and not used but I reckon it leads to a nice "just proxy these with python" feature in the future without too much noise.
url = context.url_from_query() | ||
|
||
content_iterable = request.find_service(HTTPService).stream( | ||
url, headers=add_request_headers({}) | ||
url, headers=add_request_headers({}, request=request) |
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.
Passing the request here get the original headers.
return self._proxy_onedrive_pdf(url) | ||
return self._proxy_python_pdf(url, route="proxy_onedrive_pdf") | ||
|
||
if self._is_d2l_url(url): |
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.
I briefly tried the nginx approach but not sure if it was possible to:
- Pass the headers to nginx in a secure way
- Do that in a way that involved sane code.
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.
Not much to say, this all looks sensible.
It might be worth having a check in New Relic at some point to see how Via's performance is doing with now proxying lots of files in Python instead of NGINX.
19b719d
to
fc4f5f1
Compare
Decrypt and proxy the contents of `via.secret.headers` as headers to the downstream server.
Use the python proxying infrastructure to proxy D2L files. Note that the actual proxying process is the same as for MS OneDrive files but we keep multiple url/routes in case we need reporting in both or different proxying requirements at another level (eg CloudFlare).
fc4f5f1
to
bd540b9
Compare
Needs hypothesis/h-vialib#42 merged and published before CI is green.
For
Testing
Follow the instructions over: hypothesis/lms#4792