Plug + Bandit Elixir
/pixel.gif 요청에 빈 GIF로 응답하는 Plug + Bandit용 Elixir 스니펫입니다. GIF는 시작할 때 한 번만 디코딩합니다.
Plug + Bandit Elixir
Mix.install([:plug, :bandit])
defmodule Pixel.Router do
use Plug.Router
@gif Base.decode64!("R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==")
plug :match
plug :dispatch
get "/pixel.gif" do
conn
|> put_resp_content_type("image/gif", nil)
|> put_resp_header("cache-control", "no-store")
|> send_resp(200, @gif)
end
match _ do
send_resp(conn, 404, "Not Found")
end
end
Bandit.start_link(plug: Pixel.Router, port: 8080)
Process.sleep(:infinity)
이 스니펫은 실행해 보고, 반환된 바이트를 비교했습니다.
확인
curl -sI http://localhost:8080/pixel.gif