Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include sent headers with CONNECT request to upstream proxy #6328

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions mitmproxy/addons/proxy_forward_headers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import weakref
from collections.abc import MutableMapping

Check warning on line 2 in mitmproxy/addons/proxy_forward_headers.py

View check run for this annotation

Codecov / codecov/patch

mitmproxy/addons/proxy_forward_headers.py#L1-L2

Added lines #L1 - L2 were not covered by tests

from mitmproxy import connection
from mitmproxy import ctx
from mitmproxy import http

Check warning on line 6 in mitmproxy/addons/proxy_forward_headers.py

View check run for this annotation

Codecov / codecov/patch

mitmproxy/addons/proxy_forward_headers.py#L4-L6

Added lines #L4 - L6 were not covered by tests


class ProxyForwardHeaders:
def __init__(self) -> None:
self.connection_headers: MutableMapping[

Check warning on line 11 in mitmproxy/addons/proxy_forward_headers.py

View check run for this annotation

Codecov / codecov/patch

mitmproxy/addons/proxy_forward_headers.py#L9-L11

Added lines #L9 - L11 were not covered by tests
connection.Client, tuple[str, str]
] = weakref.WeakKeyDictionary()

def load(self, loader):
loader.add_option(

Check warning on line 16 in mitmproxy/addons/proxy_forward_headers.py

View check run for this annotation

Codecov / codecov/patch

mitmproxy/addons/proxy_forward_headers.py#L15-L16

Added lines #L15 - L16 were not covered by tests
"proxyforwardheaders",
bool,
False,
"""
Forward CONNECT headers to upstream proxy.
""",
)

def http_connect(self, f: http.HTTPFlow) -> None:
if ctx.options.proxyforwardheaders:
self.connection_headers[f.client_conn] = f.request.headers

Check warning on line 27 in mitmproxy/addons/proxy_forward_headers.py

View check run for this annotation

Codecov / codecov/patch

mitmproxy/addons/proxy_forward_headers.py#L25-L27

Added lines #L25 - L27 were not covered by tests

def http_connect_upstream(self, f: http.HTTPFlow):
if ctx.options.proxyforwardheaders and self.connection_headers:
f.request.headers = self.connection_headers[f.client_conn]

Check warning on line 31 in mitmproxy/addons/proxy_forward_headers.py

View check run for this annotation

Codecov / codecov/patch

mitmproxy/addons/proxy_forward_headers.py#L29-L31

Added lines #L29 - L31 were not covered by tests


addons = [ProxyForwardHeaders()]

Check warning on line 34 in mitmproxy/addons/proxy_forward_headers.py

View check run for this annotation

Codecov / codecov/patch

mitmproxy/addons/proxy_forward_headers.py#L34

Added line #L34 was not covered by tests
Loading