Skip to content

Commit b69f22a

Browse files
authored
Merge pull request #4835 from kwlzn/kwlzn/notebook_unix_socket
Add UNIX socket support to notebook server.
2 parents 0090315 + dcc8874 commit b69f22a

8 files changed

+487
-53
lines changed

notebook/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
os.path.join(os.path.dirname(__file__), "templates"),
2121
]
2222

23+
DEFAULT_NOTEBOOK_PORT = 8888
24+
2325
del os
2426

2527
from .nbextensions import install_nbextension

notebook/base/handlers.py

+12-7
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import notebook
3333
from notebook._tz import utcnow
3434
from notebook.i18n import combine_translations
35-
from notebook.utils import is_hidden, url_path_join, url_is_absolute, url_escape
35+
from notebook.utils import is_hidden, url_path_join, url_is_absolute, url_escape, urldecode_unix_socket_path
3636
from notebook.services.security import csp_report_uri
3737

3838
#-----------------------------------------------------------------------------
@@ -471,13 +471,18 @@ def check_host(self):
471471
if host.startswith('[') and host.endswith(']'):
472472
host = host[1:-1]
473473

474-
try:
475-
addr = ipaddress.ip_address(host)
476-
except ValueError:
477-
# Not an IP address: check against hostnames
478-
allow = host in self.settings.get('local_hostnames', ['localhost'])
474+
# UNIX socket handling
475+
check_host = urldecode_unix_socket_path(host)
476+
if check_host.startswith('/') and os.path.exists(check_host):
477+
allow = True
479478
else:
480-
allow = addr.is_loopback
479+
try:
480+
addr = ipaddress.ip_address(host)
481+
except ValueError:
482+
# Not an IP address: check against hostnames
483+
allow = host in self.settings.get('local_hostnames', ['localhost'])
484+
else:
485+
allow = addr.is_loopback
481486

482487
if not allow:
483488
self.log.warning(

0 commit comments

Comments
 (0)