mitmproxy/libmproxy/protocol2/reverse_proxy.py

23 lines
802 B
Python
Raw Normal View History

2015-08-06 10:32:33 +00:00
from __future__ import (absolute_import, print_function, division)
from .layer import Layer, ServerConnectionMixin
from .tls import TlsLayer
2015-08-06 10:32:33 +00:00
class ReverseProxy(Layer, ServerConnectionMixin):
def __init__(self, ctx, server_address, client_tls, server_tls):
2015-08-16 21:25:02 +00:00
super(ReverseProxy, self).__init__(ctx, server_address=server_address)
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
2015-08-18 12:15:08 +00:00
if self.server_conn:
self._disconnect()