Skip to content

Commit

Permalink
Add handling for relative paths in Location headers
Browse files Browse the repository at this point in the history
  • Loading branch information
paulkm committed Oct 26, 2024
1 parent 35b0279 commit 8f5150a
Showing 1 changed file with 7 additions and 2 deletions.
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

0 comments on commit 8f5150a

Please sign in to comment.