Skip to content

Commit 36c8e17

Browse files
committed
Create StandaloneHubProxyHandler and timeout Argument. Fix authentication and check_origin
1 parent fae833b commit 36c8e17

File tree

2 files changed

+44
-44
lines changed

2 files changed

+44
-44
lines changed

jupyter_server_proxy/standalone/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def run(
2323
debug=False,
2424
logs=True,
2525
authtype="oauth",
26-
request_timeout=300,
26+
timeout=60,
2727
last_activity_interval=300,
2828
force_alive=True,
2929
progressive=False,
@@ -49,7 +49,7 @@ def run(
4949
prefix,
5050
list(command),
5151
authtype,
52-
request_timeout,
52+
timeout,
5353
debug,
5454
logs,
5555
progressive,
@@ -111,10 +111,10 @@ def main():
111111
help="Authentication Metod.",
112112
)
113113
parser.add_argument(
114-
"--request-timeout",
115-
default=300,
114+
"--timeout",
115+
default=60,
116116
type=int,
117-
help="Timeout for proxied HTTP calls to subprocess in seconds.",
117+
help="Timeout to wait until the subprocess has started and can be addressed.",
118118
)
119119
parser.add_argument(
120120
"--last-activity-interval",

jupyter_server_proxy/standalone/proxy.py

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from jupyterhub.utils import exponential_backoff, isoformat, make_ssl_context
1010
from tornado import httpclient, ioloop
1111
from tornado.web import Application, RedirectHandler, RequestHandler
12+
from tornado.websocket import WebSocketHandler
1213

1314
from ..handlers import SuperviseAndProxyHandler
1415

@@ -25,50 +26,47 @@ def configure_http_client():
2526
httpclient.AsyncHTTPClient.configure(None, defaults={"ssl_options": ssl_context})
2627

2728

28-
def _make_native_proxy_handler(command, environment, port, mappath):
29+
class StandaloneHubProxyHandler(SuperviseAndProxyHandler):
30+
def __init__(self, *args, **kwargs):
31+
super().__init__(*args, **kwargs)
32+
self.authtype = "oauth"
33+
self.environment = {}
34+
self.timeout = 60
35+
36+
def prepare(self, *args, **kwargs):
37+
# ToDo: Automatically disable if not spawned by JupyterHub
38+
if self.authtype == "oauth":
39+
return super().prepare(*args, **kwargs)
40+
else:
41+
pass
42+
43+
def check_origin(self, origin: str = None):
44+
# Skip JupyterHandler.check_origin
45+
return WebSocketHandler.check_origin(self, origin)
46+
47+
def get_env(self):
48+
return self._render_template(self.environment)
49+
50+
def get_timeout(self):
51+
return self.timeout
52+
53+
54+
def _make_native_proxy_handler(command, port, mappath, authtype, environment, timeout):
2955
"""
30-
Create a SuperviseAndProxyHandler subclass with given parameters
56+
Create a StandaloneHubProxyHandler subclass with given parameters
3157
"""
3258

33-
class _Proxy(SuperviseAndProxyHandler):
59+
class _Proxy(StandaloneHubProxyHandler):
3460
def __init__(self, *args, **kwargs):
3561
super().__init__(*args, **kwargs)
62+
self.name = command[0]
3663
self.proxy_base = command[0]
3764
self.requested_port = port
3865
self.mappath = mappath
3966
self.command = command
40-
41-
# ToDo?
42-
self.origin_host = None
43-
44-
# ToDo!
45-
def prepare(self, *args, **kwargs):
46-
pass
47-
48-
# ToDo!
49-
def skip_check_origin(self) -> bool:
50-
return True
51-
52-
@property
53-
def process_args(self):
54-
return {
55-
"port": self.port,
56-
"base_url": self.base_url,
57-
"origin_host": self.request.host, # ToDo!
58-
"-": "-",
59-
"--": "--",
60-
}
61-
62-
def get_env(self):
63-
if callable(environment):
64-
raise Exception(
65-
"return self._render_template(call_with_asked_args(environment, self.process_args))"
66-
)
67-
else:
68-
return self._render_template(environment)
69-
70-
def get_timeout(self):
71-
return 60
67+
self.authtype = authtype
68+
self.environment = environment
69+
self.timeout = timeout
7270

7371
return _Proxy
7472

@@ -90,15 +88,18 @@ def make_app(
9088
prefix,
9189
command,
9290
authtype,
93-
request_timeout,
91+
timeout,
9492
debug,
9593
logs,
9694
progressive,
9795
websocket_max_message_size,
9896
):
9997
patch_default_headers()
10098

101-
proxy_handler = _make_native_proxy_handler(command, {}, destport, {})
99+
# ToDo: Environment
100+
proxy_handler = _make_native_proxy_handler(
101+
command, destport, {}, authtype, {}, timeout
102+
)
102103

103104
options = dict(
104105
debug=debug,
@@ -108,7 +109,6 @@ def make_app(
108109
group=os.environ.get("JUPYTERHUB_GROUP") or "",
109110
anyone=os.environ.get("JUPYTERHUB_ANYONE") or "",
110111
base_url=prefix, # This is a confusing name, sorry
111-
request_timeout=request_timeout,
112112
)
113113

114114
if websocket_max_message_size:
@@ -125,7 +125,7 @@ def make_app(
125125
proxy_handler,
126126
dict(
127127
state={},
128-
# ToDo: authtype=authtype, progressive=progressive
128+
# ToDo: progressive=progressive
129129
),
130130
),
131131
(

0 commit comments

Comments
 (0)