Skip to content

Commit 0ce2f9f

Browse files
authored
Merge pull request #177 from oeway/patch-2
Quote proxied_path to make it a safe URL (fixes #138)
2 parents 429625a + 81b56d5 commit 0ce2f9f

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

jupyter_server_proxy/handlers.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import inspect
88
import socket
99
import os
10-
from urllib.parse import urlunparse, urlparse
10+
from urllib.parse import urlunparse, urlparse, quote
1111
import aiohttp
1212
from asyncio import Lock
1313

@@ -141,6 +141,8 @@ def get_client_uri(self, protocol, host, port, proxied_path):
141141
else:
142142
client_path = proxied_path
143143

144+
client_path = quote(client_path)
145+
144146
client_uri = '{protocol}://{host}:{port}{path}'.format(
145147
protocol=protocol,
146148
host=host,

tests/test_proxies.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import json
33
import os
44
from http.client import HTTPConnection
5+
from urllib.parse import quote
56
import pytest
67
from tornado.websocket import websocket_connect
78

@@ -19,6 +20,15 @@ def request_get(port, path, token, host='localhost'):
1920
return h.getresponse()
2021

2122

23+
def test_server_proxy_url_encoding():
24+
special_path = quote('Hellö Wörld 🎉你好世界@±¥')
25+
test_url = '/python-http/' + special_path
26+
r = request_get(PORT, test_url, TOKEN)
27+
assert r.code == 200
28+
s = r.read().decode('ascii')
29+
assert s.startswith('GET /{}?token='.format(special_path))
30+
31+
2232
def test_server_proxy_non_absolute():
2333
r = request_get(PORT, '/python-http/abc', TOKEN)
2434
assert r.code == 200

0 commit comments

Comments
 (0)