Skip to content

Commit 048f47a

Browse files
authored
Merge pull request #134 from ryanlovett/rewrite-netloc
Fix netloc when rstudio-server inserts port.
2 parents 6654028 + 95759d8 commit 048f47a

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

jupyter_rsession_proxy/__init__.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,17 @@ def get_icon_path():
3131
os.path.dirname(os.path.abspath(__file__)), 'icons', 'rstudio.svg'
3232
)
3333

34-
def rewrite_auth(response, request):
34+
def rewrite_netloc(response, request):
3535
'''
36-
As of rstudio-server 1.4ish, it would send the client to /auth-sign-in
37-
rather than what the client sees as the full URL followed by
38-
/auth-sign-in. See rstudio/rstudio#8888. We rewrite the response by
39-
sending the client to the right place.
36+
In some circumstances, rstudio-server appends a port to the URL while
37+
setting Location in the header. We rewrite the response to use the host
38+
in the request.
4039
'''
4140
for header, v in response.headers.get_all():
42-
if header == "Location" and v.startswith("/auth-sign-in"):
43-
# Visit the correct page
44-
u = urlparse(request.uri)
45-
response.headers[header] = urlunparse(u._replace(path=u.path+v))
41+
if header == "Location":
42+
u = urlparse(v)
43+
if u.netloc != request.host:
44+
response.headers[header] = urlunparse(u._replace(netloc=request.host))
4645

4746
def get_system_user():
4847
try:
@@ -113,7 +112,7 @@ def _get_timeout(default=15):
113112
'command': _get_cmd,
114113
'timeout': _get_timeout(),
115114
'environment': _get_env,
116-
'rewrite_response': rewrite_auth,
115+
'rewrite_response': rewrite_netloc,
117116
'launcher_entry': {
118117
'title': 'RStudio',
119118
'icon_path': get_icon_path()

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
keywords=['Jupyter'],
1111
classifiers=['Framework :: Jupyter'],
1212
install_requires=[
13-
'jupyter-server-proxy>=3.2.0'
13+
'jupyter-server-proxy>=3.2.2'
1414
],
1515
entry_points={
1616
'jupyter_serverproxy_servers': [

0 commit comments

Comments
 (0)