99from jupyterhub .utils import exponential_backoff , isoformat , make_ssl_context
1010from tornado import httpclient , ioloop
1111from tornado .web import Application , RedirectHandler , RequestHandler
12+ from tornado .websocket import WebSocketHandler
1213
1314from ..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