aboutsummaryrefslogtreecommitdiffstats
path: root/examples/upsidedownternet.py
blob: d5059092219774e6e419b36445da5be00b3908a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
from six.moves import cStringIO as StringIO
from PIL import Image


def response(flow):
    if flow.response.headers.get("content-type", "").startswith("image"):
        try:
            s = StringIO(flow.response.content)
            img = Image.open(s).rotate(180)
            s2 = StringIO()
            img.save(s2, "png")
            flow.response.content = s2.getvalue()
            flow.response.headers["content-type"] = "image/png"
        except:  # Unknown image types etc.
            pass