aboutsummaryrefslogtreecommitdiffstats
path: root/examples/simple/upsidedownternet.py
blob: f150a5c37c187acf49d31dd8002b7f825d7f4f9d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
"""
This script rotates all images passing through the proxy by 180 degrees.
"""
import io
from PIL import Image
from mitmproxy import http


def response(flow: http.HTTPFlow) -> None:
    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"