Phoenix Elixir
A Elixir snippet for Phoenix that answers requests for /pixel.gif with the empty GIF, decoded once at startup.
Phoenix Elixir
# lib/my_app_web/controllers/pixel_controller.ex
defmodule MyAppWeb.PixelController do
use MyAppWeb, :controller
# Decoded once, at compile time.
@gif Base.decode64!("R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==")
def show(conn, _params) do
conn
|> put_resp_content_type("image/gif", nil)
|> put_resp_header("cache-control", "no-store")
|> send_resp(200, @gif)
end
end
# lib/my_app_web/router.ex - outside the :browser pipeline (no session cookie, no CSRF)
scope "/", MyAppWeb do
get "/pixel.gif", PixelController, :show
end
We ran this snippet and compared the bytes it returned.
Check it
curl -sI http://localhost:8080/pixel.gif