mirror of
https://github.com/mitmproxy/mitmproxy.git
synced 2024-12-13 16:16:43 +00:00
18 lines
672 B
Python
18 lines
672 B
Python
import cStringIO
|
|
from PIL import Image
|
|
from libmproxy.protocol.http import decoded
|
|
|
|
|
|
def response(context, flow):
|
|
if flow.response.headers.get_first("content-type", "").startswith("image"):
|
|
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()
|
|
flow.response.headers["content-type"] = ["image/png"]
|
|
except: # Unknown image types etc.
|
|
pass
|