2016-11-21 01:16:20 +00:00
|
|
|
"""
|
|
|
|
This script rotates all images passing through the proxy by 180 degrees.
|
|
|
|
"""
|
|
|
|
import io
|
|
|
|
from PIL import Image
|
2017-04-28 21:56:14 +00:00
|
|
|
from mitmproxy import http
|
2016-11-21 01:16:20 +00:00
|
|
|
|
|
|
|
|
2017-04-28 21:56:14 +00:00
|
|
|
def response(flow: http.HTTPFlow) -> None:
|
2016-11-21 01:16:20 +00:00
|
|
|
if flow.response.headers.get("content-type", "").startswith("image"):
|
|
|
|
s = io.BytesIO(flow.response.content)
|
|
|
|
img = Image.open(s).rotate(180)
|
|
|
|
s2 = io.BytesIO()
|
|
|
|
img.save(s2, "png")
|
|
|
|
flow.response.content = s2.getvalue()
|
|
|
|
flow.response.headers["content-type"] = "image/png"
|