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)