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 मध्ये आणखी