aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy/proxy.py
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2011-03-09 20:05:30 +1300
committerAldo Cortesi <aldo@nullcube.com>2011-03-09 20:05:30 +1300
commite99b1d1949c6a140895f8f10c4863ec41528cccf (patch)
treed537fd7ebfdeb7b2001d0ecda723ef486b0d7475 /libmproxy/proxy.py
parent03f13453856e3af15dc3af81adcf3a80d1358da0 (diff)
downloadmitmproxy-e99b1d1949c6a140895f8f10c4863ec41528cccf.tar.gz
mitmproxy-e99b1d1949c6a140895f8f10c4863ec41528cccf.tar.bz2
mitmproxy-e99b1d1949c6a140895f8f10c4863ec41528cccf.zip
Stub out refresh for server-side replay.
Diffstat (limited to 'libmproxy/proxy.py')
-rw-r--r--libmproxy/proxy.py27
1 files changed, 26 insertions, 1 deletions
diff --git a/libmproxy/proxy.py b/libmproxy/proxy.py
index 48884c09..3a3db2e7 100644
--- a/libmproxy/proxy.py
+++ b/libmproxy/proxy.py
@@ -5,7 +5,8 @@
Development started from Neil Schemenauer's munchy.py
"""
-import sys, os, string, socket, urlparse, re, select, copy, base64
+import sys, os, string, socket, urlparse, re, select, copy, base64, time
+from email.utils import parsedate_tz, formatdate, mktime_tz
import shutil, tempfile
import optparse, SocketServer, ssl
import utils, controller
@@ -280,6 +281,30 @@ class Response(controller.Msg):
controller.Msg.__init__(self)
self.replay = False
+ def refresh(self, now=None):
+ """
+ This fairly complex and heuristic function refreshes a server
+ response for replay.
+
+ - It adjusts date, expires and last-modified headers.
+ - It adjusts cookie expiration.
+ """
+ if not now:
+ now = time.time()
+ delta = now - self.timestamp
+ refresh_headers = [
+ "date",
+ "expires",
+ "last-modified",
+ ]
+ for i in refresh_headers:
+ if i in self.headers:
+ d = parsedate_tz(self.headers[i][0])
+ new = mktime_tz(d) + delta
+ self.headers[i] = [formatdate(new)]
+ for i in self.headers.get("set-cookie", []):
+ pass
+
def set_replay(self):
self.replay = True