From 8126737fffaa8af1dfffa3361d72982a4e6bb03c Mon Sep 17 00:00:00 2001 From: ryanlovett Date: Tue, 13 Sep 2022 22:26:09 -0700 Subject: [PATCH 1/2] Fix netloc when rstudio-server inserts port. --- jupyter_rsession_proxy/__init__.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/jupyter_rsession_proxy/__init__.py b/jupyter_rsession_proxy/__init__.py index 3324bbc..f3c6734 100644 --- a/jupyter_rsession_proxy/__init__.py +++ b/jupyter_rsession_proxy/__init__.py @@ -31,18 +31,17 @@ def get_icon_path(): os.path.dirname(os.path.abspath(__file__)), 'icons', 'rstudio.svg' ) -def rewrite_auth(response, request): +def rewrite_netloc(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. + In some circumstances, rstudio-server appends a port to the URL while + setting Location in the header. We rewrite the response to use the host + in the request. ''' for header, v in response.headers.get_all(): - if header == "Location" and v.startswith("/auth-sign-in"): - # Visit the correct page - u = urlparse(request.uri) - response.headers[header] = urlunparse(u._replace(path=u.path+v)) + if header == "Location": + u = urlparse(v) + if u.netloc != request.host: + response.headers[header] = urlunparse(u._replace(netloc=request.host)) def get_system_user(): try: @@ -113,7 +112,7 @@ def _get_timeout(default=15): 'command': _get_cmd, 'timeout': _get_timeout(), 'environment': _get_env, - 'rewrite_response': rewrite_auth, + 'rewrite_response': rewrite_netloc, 'launcher_entry': { 'title': 'RStudio', 'icon_path': get_icon_path() From 95759d85e95de6cb102702762d23f74ae2d46baa Mon Sep 17 00:00:00 2001 From: ryanlovett Date: Tue, 13 Sep 2022 23:03:12 -0700 Subject: [PATCH 2/2] Require jupyter-server-proxy 3.2.2. It obviates the need for the auth rewrite. --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 18d7937..e0433a4 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ keywords=['Jupyter'], classifiers=['Framework :: Jupyter'], install_requires=[ - 'jupyter-server-proxy>=3.2.0' + 'jupyter-server-proxy>=3.2.2' ], entry_points={ 'jupyter_serverproxy_servers': [