emptygif
भाषा: हिन्दी

सभी भाषाएँ और फ़्रेमवर्क

Nim standard library (asynchttpserver) Nim

Nim standard library (asynchttpserver) के लिए Nim स्निपेट, जो /pixel.gif पर आने वाली रिक्वेस्ट का जवाब empty GIF से देता है। GIF स्टार्टअप पर एक ही बार डिकोड होता है।

Nim standard library (asynchttpserver) Nim

फ़ाइल
server.nim
चलाएँ
nim c -r -d:release server.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

आधिकारिक साइट: Nim standard library (asynchttpserver)