aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mitmproxy/addons/proxyauth.py7
-rw-r--r--test/mitmproxy/addons/test_proxyauth.py1
2 files changed, 5 insertions, 3 deletions
diff --git a/mitmproxy/addons/proxyauth.py b/mitmproxy/addons/proxyauth.py
index 61477658..43677f61 100644
--- a/mitmproxy/addons/proxyauth.py
+++ b/mitmproxy/addons/proxyauth.py
@@ -1,7 +1,7 @@
import binascii
import weakref
from typing import Optional
-from typing import Set # noqa
+from typing import MutableMapping # noqa
from typing import Tuple
import passlib.apache
@@ -46,7 +46,7 @@ class ProxyAuth:
self.htpasswd = None
self.singleuser = None
self.mode = None
- self.authenticated = weakref.WeakSet() # type: Set[connections.ClientConnection]
+ self.authenticated = weakref.WeakKeyDictionary() # type: MutableMapping[connections.ClientConnection, Tuple[str, str]]
"""Contains all connections that are permanently authenticated after an HTTP CONNECT"""
def enabled(self) -> bool:
@@ -153,11 +153,12 @@ class ProxyAuth:
def http_connect(self, f: http.HTTPFlow) -> None:
if self.enabled():
if self.authenticate(f):
- self.authenticated.add(f.client_conn)
+ self.authenticated[f.client_conn] = f.metadata["proxyauth"]
def requestheaders(self, f: http.HTTPFlow) -> None:
if self.enabled():
# Is this connection authenticated by a previous HTTP CONNECT?
if f.client_conn in self.authenticated:
+ f.metadata["proxyauth"] = self.authenticated[f.client_conn]
return
self.authenticate(f)
diff --git a/test/mitmproxy/addons/test_proxyauth.py b/test/mitmproxy/addons/test_proxyauth.py
index 14782755..513f3f08 100644
--- a/test/mitmproxy/addons/test_proxyauth.py
+++ b/test/mitmproxy/addons/test_proxyauth.py
@@ -173,3 +173,4 @@ def test_handlers():
f2 = tflow.tflow(client_conn=f.client_conn)
up.requestheaders(f2)
assert not f2.response
+ assert f2.metadata["proxyauth"] == ('test', 'test')