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)