Skip to content

Commit

Permalink
Merge pull request #4835 from kwlzn/kwlzn/notebook_unix_socket
Browse files Browse the repository at this point in the history
Add UNIX socket support to notebook server.
  • Loading branch information
blink1073 authored May 15, 2020
2 parents 0090315 + dcc8874 commit b69f22a
Show file tree
Hide file tree
Showing 8 changed files with 487 additions and 53 deletions.
2 changes: 2 additions & 0 deletions notebook/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
os.path.join(os.path.dirname(__file__), "templates"),
]

DEFAULT_NOTEBOOK_PORT = 8888

del os

from .nbextensions import install_nbextension
Expand Down
19 changes: 12 additions & 7 deletions notebook/base/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import notebook
from notebook._tz import utcnow
from notebook.i18n import combine_translations
from notebook.utils import is_hidden, url_path_join, url_is_absolute, url_escape
from notebook.utils import is_hidden, url_path_join, url_is_absolute, url_escape, urldecode_unix_socket_path
from notebook.services.security import csp_report_uri

#-----------------------------------------------------------------------------
Expand Down Expand Up @@ -471,13 +471,18 @@ def check_host(self):
if host.startswith('[') and host.endswith(']'):
host = host[1:-1]

try:
addr = ipaddress.ip_address(host)
except ValueError:
# Not an IP address: check against hostnames
allow = host in self.settings.get('local_hostnames', ['localhost'])
# UNIX socket handling
check_host = urldecode_unix_socket_path(host)
if check_host.startswith('/') and os.path.exists(check_host):
allow = True
else:
allow = addr.is_loopback
try:
addr = ipaddress.ip_address(host)
except ValueError:
# Not an IP address: check against hostnames
allow = host in self.settings.get('local_hostnames', ['localhost'])
else:
allow = addr.is_loopback

if not allow:
self.log.warning(
Expand Down
Loading

0 comments on commit b69f22a

Please sign in to comment.