Skip to content

Commit

Permalink
Merge pull request #134 from ryanlovett/rewrite-netloc
Browse files Browse the repository at this point in the history
Fix netloc when rstudio-server inserts port.
  • Loading branch information
ryanlovett committed Sep 24, 2022
2 parents 6654028 + 95759d8 commit 048f47a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
19 changes: 9 additions & 10 deletions jupyter_rsession_proxy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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': [
Expand Down

0 comments on commit 048f47a

Please sign in to comment.