aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy/proxy.py
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2011-03-11 11:56:10 +1300
committerAldo Cortesi <aldo@nullcube.com>2011-03-11 11:56:10 +1300
commitdaa9653ebebe73e1056d6dae14b11b0842ecbc2a (patch)
tree570350fc9807ea7c58a77f1bd3f31e950b86cc33 /libmproxy/proxy.py
parente99b1d1949c6a140895f8f10c4863ec41528cccf (diff)
downloadmitmproxy-daa9653ebebe73e1056d6dae14b11b0842ecbc2a.tar.gz
mitmproxy-daa9653ebebe73e1056d6dae14b11b0842ecbc2a.tar.bz2
mitmproxy-daa9653ebebe73e1056d6dae14b11b0842ecbc2a.zip
Add --norefresh to stop refreshing server playback to mitmdump.
Also, make cookie parsing for refreshing more error-tolerant.
Diffstat (limited to 'libmproxy/proxy.py')
-rw-r--r--libmproxy/proxy.py29
1 files changed, 27 insertions, 2 deletions
diff --git a/libmproxy/proxy.py b/libmproxy/proxy.py
index 3a3db2e7..caa93f58 100644
--- a/libmproxy/proxy.py
+++ b/libmproxy/proxy.py
@@ -5,7 +5,7 @@
Development started from Neil Schemenauer's munchy.py
"""
-import sys, os, string, socket, urlparse, re, select, copy, base64, time
+import sys, os, string, socket, urlparse, re, select, copy, base64, time, Cookie
from email.utils import parsedate_tz, formatdate, mktime_tz
import shutil, tempfile
import optparse, SocketServer, ssl
@@ -281,6 +281,28 @@ class Response(controller.Msg):
controller.Msg.__init__(self)
self.replay = False
+ def _refresh_cookie(self, c, delta):
+ """
+ Takes a cookie string c and a time delta in seconds, and returns
+ a refreshed cookie string.
+ """
+ c = Cookie.SimpleCookie(str(c))
+ for i in c.values():
+ if "expires" in i:
+ d = parsedate_tz(i["expires"])
+ if d:
+ d = mktime_tz(d) + delta
+ i["expires"] = formatdate(d)
+ else:
+ # This can happen when the expires tag is invalid.
+ # reddit.com sends a an expires tag like this: "Thu, 31 Dec
+ # 2037 23:59:59 GMT", which is valid RFC 1123, but not
+ # strictly correct according tot he cookie spec. Browsers
+ # appear to parse this tolerantly - maybe we should too.
+ # For now, we just ignore this.
+ del i["expires"]
+ return c.output(header="").strip()
+
def refresh(self, now=None):
"""
This fairly complex and heuristic function refreshes a server
@@ -302,8 +324,11 @@ class Response(controller.Msg):
d = parsedate_tz(self.headers[i][0])
new = mktime_tz(d) + delta
self.headers[i] = [formatdate(new)]
+ c = []
for i in self.headers.get("set-cookie", []):
- pass
+ c.append(self._refresh_cookie(i, delta))
+ if c:
+ self.headers["set-cookie"] = c
def set_replay(self):
self.replay = True