proxy.py/proxy/plugin/man_in_the_middle.py

37 lines
1.1 KiB
Python

# -*- coding: utf-8 -*-
"""
proxy.py
~~~~~~~~
⚡⚡⚡ Fast, Lightweight, Pluggable, TLS interception capable proxy server focused on
Network monitoring, controls & Application development, testing, debugging.
:copyright: (c) 2013-present by Abhinav Singh and contributors.
:license: BSD, see LICENSE for more details.
"""
from typing import Optional
from ..common.utils import build_http_response
from ..http.parser import HttpParser
from ..http.codes import httpStatusCodes
from ..http.proxy import HttpProxyBasePlugin
class ManInTheMiddlePlugin(HttpProxyBasePlugin):
"""Modifies upstream server responses."""
def before_upstream_connection(
self, request: HttpParser) -> Optional[HttpParser]:
return request
def handle_client_request(
self, request: HttpParser) -> Optional[HttpParser]:
return request
def handle_upstream_chunk(self, chunk: memoryview) -> memoryview:
return memoryview(build_http_response(
httpStatusCodes.OK,
reason=b'OK', body=b'Hello from man in the middle'))
def on_upstream_connection_close(self) -> None:
pass