@@ -44,6 +44,7 @@ def __init__(self, *args, **kwargs):
44
44
self .proxy_base = ''
45
45
self .absolute_url = kwargs .pop ('absolute_url' , False )
46
46
self .host_whitelist = kwargs .pop ('host_whitelist' , ['localhost' , '127.0.0.1' ])
47
+ self .ssl_options = kwargs .pop ('ssl_options' , None )
47
48
super ().__init__ (* args , ** kwargs )
48
49
49
50
# Support all the methods that tornado does by default except for GET which
@@ -155,7 +156,8 @@ def _build_proxy_request(self, host, port, proxied_path, body):
155
156
156
157
headers = self .proxy_request_headers ()
157
158
158
- client_uri = self .get_client_uri ('http' , host , port , proxied_path )
159
+ protocol = 'http' if self .ssl_options is None else 'https'
160
+ client_uri = self .get_client_uri (protocol , host , port , proxied_path )
159
161
# Some applications check X-Forwarded-Context and X-ProxyContextPath
160
162
# headers to see if and where they are being proxied from.
161
163
if not self .absolute_url :
@@ -251,7 +253,8 @@ async def proxy_open(self, host, port, proxied_path=''):
251
253
if not proxied_path .startswith ('/' ):
252
254
proxied_path = '/' + proxied_path
253
255
254
- client_uri = self .get_client_uri ('ws' , host , port , proxied_path )
256
+ protocol = 'ws' if self .ssl_options is None else 'wss'
257
+ client_uri = self .get_client_uri (protocol , host , port , proxied_path )
255
258
headers = self .request .headers
256
259
current_loop = ioloop .IOLoop .current ()
257
260
ws_connected = current_loop .asyncio_loop .create_future ()
@@ -282,7 +285,8 @@ def ping_cb(data):
282
285
async def start_websocket_connection ():
283
286
self .log .info ('Trying to establish websocket connection to {}' .format (client_uri ))
284
287
self ._record_activity ()
285
- request = httpclient .HTTPRequest (url = client_uri , headers = headers )
288
+ request = httpclient .HTTPRequest (url = client_uri , headers = headers ,
289
+ ssl_options = self .ssl_options )
286
290
self .ws = await pingable_ws_connect (request = request ,
287
291
on_message_callback = message_cb , on_ping_callback = ping_cb )
288
292
ws_connected .set_result (True )
@@ -304,7 +308,7 @@ def proxy_request_headers(self):
304
308
def proxy_request_options (self ):
305
309
'''A dictionary of options to be used when constructing
306
310
a tornado.httpclient.HTTPRequest instance for the proxy request.'''
307
- return dict (follow_redirects = False )
311
+ return dict (follow_redirects = False , ssl_options = self . ssl_options )
308
312
309
313
def check_xsrf_cookie (self ):
310
314
'''
@@ -529,17 +533,21 @@ def options(self, path):
529
533
return self .proxy (self .port , path )
530
534
531
535
532
- def setup_handlers (web_app , host_whitelist ):
536
+ def setup_handlers (web_app , host_whitelist , ssl_options ):
533
537
host_pattern = '.*$'
534
538
web_app .add_handlers ('.*' , [
535
539
(url_path_join (web_app .settings ['base_url' ], r'/proxy/(.*):(\d+)(.*)' ),
536
- RemoteProxyHandler , {'absolute_url' : False , 'host_whitelist' : host_whitelist }),
540
+ RemoteProxyHandler , {'absolute_url' : False , 'host_whitelist' : host_whitelist ,
541
+ 'ssl_options' : ssl_options }),
537
542
(url_path_join (web_app .settings ['base_url' ], r'/proxy/absolute/(.*):(\d+)(.*)' ),
538
- RemoteProxyHandler , {'absolute_url' : True , 'host_whitelist' : host_whitelist }),
543
+ RemoteProxyHandler , {'absolute_url' : True , 'host_whitelist' : host_whitelist ,
544
+ 'ssl_options' : ssl_options }),
539
545
(url_path_join (web_app .settings ['base_url' ], r'/proxy/(\d+)(.*)' ),
540
- LocalProxyHandler , {'absolute_url' : False }),
546
+ LocalProxyHandler , {'absolute_url' : False ,
547
+ 'ssl_options' : ssl_options }),
541
548
(url_path_join (web_app .settings ['base_url' ], r'/proxy/absolute/(\d+)(.*)' ),
542
- LocalProxyHandler , {'absolute_url' : True }),
549
+ LocalProxyHandler , {'absolute_url' : True ,
550
+ 'ssl_options' : ssl_options }),
543
551
])
544
552
545
553
# vim: set et ts=4 sw=4:
0 commit comments