Crystal standard library (HTTP::Server) Crystal
Snippet na Crystal don Crystal standard library (HTTP::Server) da ke amsa requests zuwa /pixel.gif da empty GIF, wanda ake decoding ɗinsa sau ɗaya lokacin farawa.
Crystal standard library (HTTP::Server) Crystal
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
An duba shi da takardun bayani na yanzu na framework ɗin.
Duba shi
curl -sI http://localhost:8080/pixel.gif
Shafin hukuma: Crystal standard library (HTTP::Server)