emptygif
Dil: Türkçe

Tüm diller ve framework'ler

Tornado Python

Tornado için, /pixel.gif isteklerine başlangıçta bir kez çözülen boş GIF ile yanıt veren bir Python örneği.

Tornado Python

Kurulum
pip install tornado
Dosya
app.py
Çalıştır
python app.py
import asyncio
import base64
import re

import tornado.web

GIF = base64.b64decode("R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==")


class PixelHandler(tornado.web.RequestHandler):
    def get(self) -> None:
        self.set_header("Content-Type", "image/gif")
        self.set_header("Cache-Control", "no-store")
        self.write(GIF)


async def main() -> None:
    # Tornado routes are regular expressions, so escape the literal path.
    app = tornado.web.Application([(re.escape("/pixel.gif"), PixelHandler)])
    app.listen(8080)
    await asyncio.Event().wait()


if __name__ == "__main__":
    asyncio.run(main())

Bu örneği çalıştırıp döndürdüğü baytları karşılaştırdık.

Kontrol et

curl -sI http://localhost:8080/pixel.gif

Resmî site: Tornado

Python için daha fazlası