Nim standard library (asynchttpserver) Nim
/pixel.gif కు వచ్చే రిక్వెస్ట్లకు empty GIF తో జవాబిచ్చే, Nim standard library (asynchttpserver) కోసం Nim స్నిపెట్. GIF స్టార్టప్లో ఒక్కసారే డీకోడ్ అవుతుంది.
Nim standard library (asynchttpserver) Nim
import std/[asyncdispatch, asynchttpserver, base64]
# Decoded at compile time; a const is also safe to use from the gcsafe callback.
const gif = decode("R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==")
proc handler(req: Request) {.async.} =
if req.reqMethod == HttpGet and req.url.path == "/pixel.gif":
let headers = newHttpHeaders({"Content-Type": "image/gif", "Cache-Control": "no-store"})
await req.respond(Http200, gif, headers)
else:
await req.respond(Http404, "Not Found")
let server = newAsyncHttpServer()
waitFor server.serve(Port(8080), handler)
ఫ్రేమ్వర్క్ ప్రస్తుత డాక్యుమెంటేషన్తో పోల్చి చెక్ చేశాం.
చెక్ చేయండి
curl -sI http://localhost:8080/pixel.gif