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

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

Crystal standard library (HTTP::Server) Crystal

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

Crystal standard library (HTTP::Server) Crystal

फ़ाइल
server.cr
चलाएँ
crystal run server.cr
require "base64"
require "http/server"

GIF = Base64.decode("R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==")

server = HTTP::Server.new do |context|
  request, response = context.request, context.response
  if request.method == "GET" && request.path == "/pixel.gif"
    response.content_type = "image/gif"
    response.headers["Cache-Control"] = "no-store"
    response.content_length = GIF.size
    response.write(GIF)
  else
    response.respond_with_status(:not_found)
  end
end

server.bind_tcp "0.0.0.0", 8080
server.listen

फ़्रेमवर्क के मौजूदा डॉक्यूमेंटेशन से मिलाकर जाँचा गया।

जाँचें

curl -sI http://localhost:8080/pixel.gif

आधिकारिक साइट: Crystal standard library (HTTP::Server)

Crystal में और