-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
33cc04e
commit 47dba42
Showing
4 changed files
with
60 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
"""Upstream proxy module.""" | ||
|
||
import http_tools.settings as settings | ||
|
||
from mitmproxy import ctx | ||
from mitmproxy import http | ||
from mitmproxy.connection import Server | ||
from mitmproxy.net.server_spec import ServerSpec | ||
|
||
|
||
def load(loader): | ||
loader.add_option( | ||
name='proxy_ip', | ||
typespec=str, | ||
default='127.0.0.1', | ||
help='Upstream Proxy IP', | ||
) | ||
loader.add_option( | ||
name='proxy_port', | ||
typespec=int, | ||
default=8000, | ||
help='Upstream Proxy Port', | ||
) | ||
|
||
|
||
def request(flow: http.HTTPFlow) -> None: | ||
if (flow.request.url.endswith('/kill') | ||
and flow.request.method == 'GET' | ||
and flow.request.port == settings.PROXY_PORT): | ||
# Prevent killing the proxy server | ||
flow.kill() | ||
|
||
address = (ctx.options.proxy_ip, ctx.options.proxy_port) | ||
# Check if the server connection already exists | ||
if flow.server_conn.timestamp_start: | ||
# Replace the existing server connection with a new one | ||
flow.server_conn = Server(address=flow.server_conn.address) | ||
|
||
# Set the upstream proxy (via) server | ||
flow.server_conn.via = ServerSpec(('http', address)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters