@@ -45,6 +45,7 @@ def __init__(self, *args, **kwargs):
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
47
self .subprotocols = None
48
+ self .ssl_options = kwargs .pop ('ssl_options' , None )
48
49
super ().__init__ (* args , ** kwargs )
49
50
50
51
# Support all the methods that tornado does by default except for GET which
@@ -165,7 +166,8 @@ def _build_proxy_request(self, host, port, proxied_path, body):
165
166
166
167
headers = self .proxy_request_headers ()
167
168
168
- client_uri = self .get_client_uri ('http' , host , port , proxied_path )
169
+ protocol = 'http' if self .ssl_options is None else 'https'
170
+ client_uri = self .get_client_uri (protocol , host , port , proxied_path )
169
171
# Some applications check X-Forwarded-Context and X-ProxyContextPath
170
172
# headers to see if and where they are being proxied from.
171
173
if not self .absolute_url :
@@ -276,7 +278,8 @@ async def proxy_open(self, host, port, proxied_path=''):
276
278
if not proxied_path .startswith ('/' ):
277
279
proxied_path = '/' + proxied_path
278
280
279
- client_uri = self .get_client_uri ('ws' , host , port , proxied_path )
281
+ protocol = 'ws' if self .ssl_options is None else 'wss'
282
+ client_uri = self .get_client_uri (protocol , host , port , proxied_path )
280
283
headers = self .request .headers
281
284
current_loop = ioloop .IOLoop .current ()
282
285
ws_connected = current_loop .asyncio_loop .create_future ()
@@ -307,7 +310,8 @@ def ping_cb(data):
307
310
async def start_websocket_connection ():
308
311
self .log .info ('Trying to establish websocket connection to {}' .format (client_uri ))
309
312
self ._record_activity ()
310
- request = httpclient .HTTPRequest (url = client_uri , headers = headers )
313
+ request = httpclient .HTTPRequest (url = client_uri , headers = headers ,
314
+ ssl_options = self .ssl_options )
311
315
self .ws = await pingable_ws_connect (request = request ,
312
316
on_message_callback = message_cb , on_ping_callback = ping_cb ,
313
317
subprotocols = self .subprotocols )
@@ -330,7 +334,11 @@ def proxy_request_headers(self):
330
334
def proxy_request_options (self ):
331
335
'''A dictionary of options to be used when constructing
332
336
a tornado.httpclient.HTTPRequest instance for the proxy request.'''
337
+ < << << << HEAD
333
338
return dict (follow_redirects = False , connect_timeout = 250.0 , request_timeout = 300.0 )
339
+ == == == =
340
+ return dict (follow_redirects = False , ssl_options = self .ssl_options )
341
+ >> >> >> > Enable SSL on forwarded requests
334
342
335
343
def check_xsrf_cookie (self ):
336
344
'''
@@ -556,17 +564,21 @@ def options(self, path):
556
564
return self .proxy (self .port , path )
557
565
558
566
559
- def setup_handlers (web_app , host_whitelist ):
567
+ def setup_handlers (web_app , host_whitelist , ssl_options ):
560
568
host_pattern = '.*$'
561
569
web_app .add_handlers ('.*' , [
562
570
(url_path_join (web_app .settings ['base_url' ], r'/proxy/(.*):(\d+)(.*)' ),
563
- RemoteProxyHandler , {'absolute_url' : False , 'host_whitelist' : host_whitelist }),
571
+ RemoteProxyHandler , {'absolute_url' : False , 'host_whitelist' : host_whitelist ,
572
+ 'ssl_options' : ssl_options }),
564
573
(url_path_join (web_app .settings ['base_url' ], r'/proxy/absolute/(.*):(\d+)(.*)' ),
565
- RemoteProxyHandler , {'absolute_url' : True , 'host_whitelist' : host_whitelist }),
574
+ RemoteProxyHandler , {'absolute_url' : True , 'host_whitelist' : host_whitelist ,
575
+ 'ssl_options' : ssl_options }),
566
576
(url_path_join (web_app .settings ['base_url' ], r'/proxy/(\d+)(.*)' ),
567
- LocalProxyHandler , {'absolute_url' : False }),
577
+ LocalProxyHandler , {'absolute_url' : False ,
578
+ 'ssl_options' : ssl_options }),
568
579
(url_path_join (web_app .settings ['base_url' ], r'/proxy/absolute/(\d+)(.*)' ),
569
- LocalProxyHandler , {'absolute_url' : True }),
580
+ LocalProxyHandler , {'absolute_url' : True ,
581
+ 'ssl_options' : ssl_options }),
570
582
])
571
583
572
584
# vim: set et ts=4 sw=4:
0 commit comments