2014-01-04 02:15:08 +00:00
|
|
|
import cStringIO
|
|
|
|
from PIL import Image
|
2015-09-03 22:46:42 +00:00
|
|
|
from libmproxy.models import decoded
|
2014-01-04 02:15:08 +00:00
|
|
|
|
2015-05-30 00:03:28 +00:00
|
|
|
|
2014-09-08 14:02:31 +00:00
|
|
|
def response(context, flow):
|
2015-09-05 18:45:58 +00:00
|
|
|
if flow.response.headers.get("content-type", "").startswith("image"):
|
2014-09-08 14:02:31 +00:00
|
|
|
with decoded(flow.response): # automatically decode gzipped responses.
|
|
|
|
try:
|
|
|
|
s = cStringIO.StringIO(flow.response.content)
|
|
|
|
img = Image.open(s).rotate(180)
|
|
|
|
s2 = cStringIO.StringIO()
|
|
|
|
img.save(s2, "png")
|
|
|
|
flow.response.content = s2.getvalue()
|
2015-09-05 18:45:58 +00:00
|
|
|
flow.response.headers["content-type"] = "image/png"
|
2014-09-08 14:02:31 +00:00
|
|
|
except: # Unknown image types etc.
|
2015-05-30 00:03:28 +00:00
|
|
|
pass
|