Crystal standard library (HTTP::Server) Crystal
/pixel.gif 요청에 빈 GIF로 응답하는 Crystal standard library (HTTP::Server)용 Crystal 스니펫입니다. GIF는 시작할 때 한 번만 디코딩합니다.
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
프레임워크의 최신 문서와 대조해 확인했습니다.
확인
curl -sI http://localhost:8080/pixel.gif
공식 사이트: Crystal standard library (HTTP::Server)