emptygif
Basa: Basa Jawa

Kabeh basa lan framework

aiohttp Python

Snippet Python kanggo aiohttp sing mangsuli request menyang /pixel.gif nganggo empty GIF, sing didekode sepisan nalika startup.

aiohttp Python

Instal
pip install aiohttp
File
server.py
Lakokake
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)

Snippet iki wis dilakokake lan byte asile wis dibandhingake.

Priksa

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

Situs resmi: aiohttp

Liyane ing Python