@@ -43,6 +43,8 @@ class ProxyHandler(WebSocketHandlerMixin, IPythonHandler):
4343 def __init__ (self , * args , ** kwargs ):
4444 self .proxy_base = ''
4545 self .absolute_url = kwargs .pop ('absolute_url' , False )
46+ self .host_whitelist_hook = kwargs .pop ('host_whitelist_hook' ,
47+ lambda handler , host : host in ['localhost' , '127.0.0.1' ])
4648 super ().__init__ (* args , ** kwargs )
4749
4850 # Support all the methods that torando does by default except for GET which
@@ -168,9 +170,7 @@ def _build_proxy_request(self, host, port, proxied_path, body):
168170 return req
169171
170172 def _check_host_whitelist (self , host ):
171- # TODO Get whitelist from config
172- whitelist = [r'localhost' , r'127\.0\.0\.1' ]
173- return any ([bool (re .match (pattern , host )) for pattern in whitelist ])
173+ return self .host_whitelist_hook (self , host )
174174
175175 @web .authenticated
176176 async def proxy (self , host , port , proxied_path ):
@@ -521,17 +521,17 @@ def options(self, path):
521521 return self .proxy (self .port , path )
522522
523523
524- def setup_handlers (web_app ):
524+ def setup_handlers (web_app , host_whitelist_hook ):
525525 host_pattern = '.*$'
526526 web_app .add_handlers ('.*' , [
527527 (url_path_join (web_app .settings ['base_url' ], r'/proxy/(\d+)(.*)' ),
528528 LocalProxyHandler , {'absolute_url' : False }),
529529 (url_path_join (web_app .settings ['base_url' ], r'/proxy/absolute/(\d+)(.*)' ),
530530 LocalProxyHandler , {'absolute_url' : True }),
531531 (url_path_join (web_app .settings ['base_url' ], r'/proxy/(.*):(\d+)(.*)' ),
532- RemoteProxyHandler , {'absolute_url' : False }),
532+ RemoteProxyHandler , {'absolute_url' : False , 'host_whitelist_hook' : host_whitelist_hook }),
533533 (url_path_join (web_app .settings ['base_url' ], r'/proxy/absolute/(.*):(\d+)(.*)' ),
534- RemoteProxyHandler , {'absolute_url' : True }),
534+ RemoteProxyHandler , {'absolute_url' : True , 'host_whitelist_hook' : host_whitelist_hook }),
535535 ])
536536
537537# vim: set et ts=4 sw=4:
0 commit comments