From e5bb37dcdb469688e2dd838bd55c2c082681e7e9 Mon Sep 17 00:00:00 2001 From: juzdzema <101811775+juzdzema@users.noreply.github.com> Date: Thu, 17 Mar 2022 15:07:51 +0100 Subject: [PATCH] Rewrite malformed root url Fixes #121 --- jupyter_rsession_proxy/__init__.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/jupyter_rsession_proxy/__init__.py b/jupyter_rsession_proxy/__init__.py index 1dff8ca..6dd0555 100644 --- a/jupyter_rsession_proxy/__init__.py +++ b/jupyter_rsession_proxy/__init__.py @@ -32,16 +32,16 @@ def get_icon_path(): def rewrite_auth(response, request): ''' - As of rstudio-server 1.4ish, it would send the client to /auth-sign-in - rather than what the client sees as the full URL followed by - /auth-sign-in. See rstudio/rstudio#8888. We rewrite the response by - sending the client to the right place. + As of rstudio-server 1.4ish, it would send the client + to a malformed root url when behind a reverse proxy. + We rewrite the response by sending the client to the right place. ''' + correct_root_url = request.host for header, v in response.headers.get_all(): - if header == "Location" and v.startswith("/auth-sign-in"): + if header == "Location" and correct_root_url not in v: # Visit the correct page - u = urlparse(request.uri) - response.headers[header] = urlunparse(u._replace(path=u.path+v)) + u = urlparse(v) + response.headers[header] = urlunparse(u._replace(netloc=correct_root_url)) def setup_rserver(): def _get_env(port):