mirror of
https://github.com/vee1e/mitmproxy.git
synced 2026-09-02 02:37:15 +00:00
add proxy-auth header for plain http requests, fix #4728
This commit is contained in:
parent
359406e7a5
commit
416e5046bc
3 changed files with 10 additions and 12 deletions
|
|
@ -51,7 +51,7 @@ class UpstreamAuth:
|
|||
|
||||
def requestheaders(self, f: http.HTTPFlow):
|
||||
if self.auth:
|
||||
if f.mode == "upstream" and not f.server_conn.via:
|
||||
if ctx.options.mode.startswith("upstream") and f.request.scheme == "http":
|
||||
f.request.headers["Proxy-Authorization"] = self.auth
|
||||
elif ctx.options.mode.startswith("reverse"):
|
||||
f.request.headers["Authorization"] = self.auth
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ from mitmproxy.test.tutils import treq, tresp
|
|||
from wsproto.frame_protocol import Opcode
|
||||
|
||||
|
||||
def ttcpflow(client_conn=True, server_conn=True, messages=True, err=None):
|
||||
def ttcpflow(client_conn=True, server_conn=True, messages=True, err=None) -> tcp.TCPFlow:
|
||||
if client_conn is True:
|
||||
client_conn = tclient_conn()
|
||||
if server_conn is True:
|
||||
|
|
@ -91,7 +91,7 @@ def twebsocketflow(messages=True, err=None, close_code=None, close_reason='') ->
|
|||
return flow
|
||||
|
||||
|
||||
def tflow(client_conn=True, server_conn=True, req=True, resp=None, err=None):
|
||||
def tflow(client_conn=True, server_conn=True, req=True, resp=None, err=None) -> http.HTTPFlow:
|
||||
"""
|
||||
@type client_conn: bool | None | mitmproxy.proxy.connection.ClientConnection
|
||||
@type server_conn: bool | None | mitmproxy.proxy.connection.ServerConnection
|
||||
|
|
@ -126,7 +126,7 @@ class DummyFlow(flow.Flow):
|
|||
super().__init__("dummy", client_conn, server_conn, live)
|
||||
|
||||
|
||||
def tdummyflow(client_conn=True, server_conn=True, err=None):
|
||||
def tdummyflow(client_conn=True, server_conn=True, err=None) -> DummyFlow:
|
||||
if client_conn is True:
|
||||
client_conn = tclient_conn()
|
||||
if server_conn is True:
|
||||
|
|
|
|||
|
|
@ -33,20 +33,18 @@ def test_simple():
|
|||
tctx.configure(up, upstream_auth="foo:bar")
|
||||
|
||||
f = tflow.tflow()
|
||||
f.mode = "upstream"
|
||||
up.requestheaders(f)
|
||||
up.http_connect_upstream(f)
|
||||
assert "proxy-authorization" in f.request.headers
|
||||
|
||||
f = tflow.tflow()
|
||||
up.requestheaders(f)
|
||||
assert "proxy-authorization" not in f.request.headers
|
||||
assert "authorization" not in f.request.headers
|
||||
|
||||
tctx.configure(up, mode="upstream:127.0.0.1")
|
||||
up.requestheaders(f)
|
||||
assert "proxy-authorization" in f.request.headers
|
||||
|
||||
tctx.configure(up, mode="reverse:127.0.0.1")
|
||||
f = tflow.tflow()
|
||||
f.mode = "transparent"
|
||||
up.requestheaders(f)
|
||||
assert "authorization" in f.request.headers
|
||||
|
||||
f = tflow.tflow()
|
||||
up.http_connect_upstream(f)
|
||||
assert "proxy-authorization" in f.request.headers
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue