You are correct, however, you are not using conn which has before_send registered (do not forget that the variables are immutable in Elixir.)
Edit:
Plug.Conn.register_before_send(conn, fn conn ->
To:
conn = Plug.Conn.register_before_send(conn, fn conn ->
Or rewrite the function so that the value returned from register_before_send:
def my_handle(conn, _opts) do
IO.puts "== setting up =="
Plug.Conn.register_before_send(conn, fn conn ->
IO.puts "== cleaning up =="
conn
end)
end
source
share