aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShadab Zafar <dufferzafar0@gmail.com>2016-07-14 13:07:27 +0530
committerMaximilian Hils <git@maximilianhils.com>2016-07-14 00:37:27 -0700
commit126625584251d6a246ba46943cfa71d5a57fbdda (patch)
tree6431dafb9cda0a752d68b5ac3c16007297568daa
parentc852c3c88d6e8cff6ac527993a1c263cce3403ac (diff)
downloadmitmproxy-126625584251d6a246ba46943cfa71d5a57fbdda.tar.gz
mitmproxy-126625584251d6a246ba46943cfa71d5a57fbdda.tar.bz2
mitmproxy-126625584251d6a246ba46943cfa71d5a57fbdda.zip
Re-add deletion of stickycookies (#1355)
This was originally added in #1324 (fixing issue #1096) but got lost during "the big refactor" (#1352)
-rw-r--r--mitmproxy/builtins/stickycookie.py18
-rw-r--r--test/mitmproxy/builtins/test_stickycookie.py10
2 files changed, 24 insertions, 4 deletions
diff --git a/mitmproxy/builtins/stickycookie.py b/mitmproxy/builtins/stickycookie.py
index 5913976c..dc699bb4 100644
--- a/mitmproxy/builtins/stickycookie.py
+++ b/mitmproxy/builtins/stickycookie.py
@@ -46,10 +46,20 @@ class StickyCookie:
for name, (value, attrs) in flow.response.cookies.items(multi=True):
# FIXME: We now know that Cookie.py screws up some cookies with
# valid RFC 822/1123 datetime specifications for expiry. Sigh.
- a = ckey(attrs, flow)
- if domain_match(flow.request.host, a[0]):
- b = attrs.with_insert(0, name, value)
- self.jar[a][name] = b
+ dom_port_path = ckey(attrs, flow)
+
+ if domain_match(flow.request.host, dom_port_path[0]):
+ if cookies.is_expired(attrs):
+ # Remove the cookie from jar
+ self.jar[dom_port_path].pop(name, None)
+
+ # If all cookies of a dom_port_path have been removed
+ # then remove it from the jar itself
+ if not self.jar[dom_port_path]:
+ self.jar.pop(dom_port_path, None)
+ else:
+ b = attrs.with_insert(0, name, value)
+ self.jar[dom_port_path][name] = b
def request(self, flow):
if self.flt:
diff --git a/test/mitmproxy/builtins/test_stickycookie.py b/test/mitmproxy/builtins/test_stickycookie.py
index 9cf768df..b8d703bd 100644
--- a/test/mitmproxy/builtins/test_stickycookie.py
+++ b/test/mitmproxy/builtins/test_stickycookie.py
@@ -112,6 +112,16 @@ class TestStickyCookie(mastertest.MasterTest):
assert len(sc.jar[googlekey].keys()) == 1
assert list(sc.jar[googlekey]["somecookie"].items())[0][1] == "newvalue"
+ def test_response_delete(self):
+ s, m, sc = self.mk()
+
+ # Test that a cookie is be deleted
+ # by setting the expire time in the past
+ f = self._response(s, m, sc, "duffer=zafar; Path=/", "www.google.com")
+ f.response.headers["Set-Cookie"] = "duffer=; Expires=Thu, 01-Jan-1970 00:00:00 GMT"
+ self.invoke(m, "response", f)
+ assert not sc.jar.keys()
+
def test_request(self):
s, m, sc = self.mk()