2015-08-06 10:32:33 +00:00
|
|
|
from __future__ import (absolute_import, print_function, division)
|
|
|
|
|
|
|
|
from .layer import Layer, ServerConnectionMixin
|
2015-08-08 14:08:57 +00:00
|
|
|
from .tls import TlsLayer
|
2015-08-06 10:32:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ReverseProxy(Layer, ServerConnectionMixin):
|
|
|
|
|
2015-08-08 14:08:57 +00:00
|
|
|
def __init__(self, ctx, server_address, client_tls, server_tls):
|
2015-08-06 10:32:33 +00:00
|
|
|
super(ReverseProxy, self).__init__(ctx)
|
|
|
|
self.server_address = server_address
|
2015-08-08 14:08:57 +00:00
|
|
|
self._client_tls = client_tls
|
|
|
|
self._server_tls = server_tls
|
2015-08-06 10:32:33 +00:00
|
|
|
|
|
|
|
def __call__(self):
|
2015-08-14 08:41:11 +00:00
|
|
|
if self._client_tls or self._server_tls:
|
|
|
|
layer = TlsLayer(self, self._client_tls, self._server_tls)
|
|
|
|
else:
|
|
|
|
layer = self.ctx.next_layer(self)
|
2015-08-06 10:32:33 +00:00
|
|
|
for message in layer():
|
|
|
|
if not self._handle_server_message(message):
|
|
|
|
yield message
|