Skip to content
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

Add handling for relative paths in Location headers #157

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions jupyter_rsession_proxy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import tempfile
import pwd
from textwrap import dedent
from urllib.parse import urlparse, urlunparse
from urllib.parse import urlparse, urlunparse, urljoin


def get_rstudio_executable(prog):
Expand Down Expand Up @@ -40,8 +40,13 @@ def rewrite_netloc(response, request):
for header, v in response.headers.get_all():
if header == "Location":
u = urlparse(v)
redirect_path = u.path
if u.path.startswith("../"):
# R Help server sometimes responds with relative locations which
# need to be handled if changing the host part of the header.
redirect_path = urljoin(request.path, u.path)
if u.netloc != request.host:
response.headers[header] = urlunparse(u._replace(netloc=request.host))
response.headers[header] = urlunparse(u._replace(netloc=request.host, path=redirect_path))

def get_system_user():
try:
Expand Down