emptygif
Wika: Filipino

Lahat ng language at framework

aiohttp Python

Isang Python snippet para sa aiohttp na sumasagot sa mga request sa /pixel.gif gamit ang empty GIF, na isang beses lang dine-decode sa startup.

aiohttp Python

I-install
pip install aiohttp
File
server.py
Patakbuhin
python server.py
import base64

from aiohttp import web

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

routes = web.RouteTableDef()


@routes.get("/pixel.gif")
async def pixel(request: web.Request) -> web.Response:
    return web.Response(
        body=GIF, content_type="image/gif", headers={"Cache-Control": "no-store"}
    )


app = web.Application()
app.add_routes(routes)

if __name__ == "__main__":
    web.run_app(app, port=8080)

Pinatakbo namin ang snippet na ito at ikinumpara ang mga byte na ibinalik nito.

Suriin

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

Opisyal na site: aiohttp

Iba pa sa Python