Phoenix Elixir
Snippet na Elixir don Phoenix da ke amsa requests zuwa /pixel.gif da empty GIF, wanda ake decoding ɗinsa sau ɗaya lokacin farawa.
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
Mun gudanar da wannan snippet kuma mun kwatanta bytes ɗin da ya mayar.
Duba shi
curl -sI http://localhost:8080/pixel.gif