emptygif
زبان: اردو

تمام زبانیں اور فریم ورکس

Nim standard library (asynchttpserver) Nim

Nim standard library (asynchttpserver) کے لیے Nim کا اسنیپٹ جو /pixel.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)