Skip to content

Commit aa2ba60

Browse files
authored
Merge pull request #157 from paulkm/fix-help-links-bug
Add handling for relative paths in Location headers
2 parents 30ad064 + 8f5150a commit aa2ba60

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

jupyter_rsession_proxy/__init__.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import tempfile
77
import pwd
88
from textwrap import dedent
9-
from urllib.parse import urlparse, urlunparse
9+
from urllib.parse import urlparse, urlunparse, urljoin
1010

1111

1212
def get_rstudio_executable(prog):
@@ -40,8 +40,13 @@ def rewrite_netloc(response, request):
4040
for header, v in response.headers.get_all():
4141
if header == "Location":
4242
u = urlparse(v)
43+
redirect_path = u.path
44+
if u.path.startswith("../"):
45+
# R Help server sometimes responds with relative locations which
46+
# need to be handled if changing the host part of the header.
47+
redirect_path = urljoin(request.path, u.path)
4348
if u.netloc != request.host:
44-
response.headers[header] = urlunparse(u._replace(netloc=request.host))
49+
response.headers[header] = urlunparse(u._replace(netloc=request.host, path=redirect_path))
4550

4651
def get_system_user():
4752
try:

0 commit comments

Comments
 (0)