Skip to content

Instantly share code, notes, and snippets.

@lukeledet
Last active April 21, 2020 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukeledet/84a5b5ef1c9f7cbe42ada2a9e10e2686 to your computer and use it in GitHub Desktop.
Save lukeledet/84a5b5ef1c9f7cbe42ada2a9e10e2686 to your computer and use it in GitHub Desktop.
Debug HTTP headers plug
defmodule Plug.DebugHTTPHeaders do
@moduledoc """
Plug to debug request and response headers. Add it to TSSWeb.Endpoint before
any other plugs to ensure you see all headers. If you add it to the router
another plug might handle the response before this one.
THIS IS MEANT FOR USE IN DEVELOPMENT ONLY.
If you see this plug used in a pull request, reject it.
"""
def init(opts) do
opts
end
def call(conn, _) do
IO.inspect(conn.req_headers, label: "Request headers")
Plug.Conn.register_before_send(conn, fn conn ->
IO.inspect(conn.resp_headers, label: "Response headers")
conn
end)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment