Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
defmodule BodyReader do
def read_body(conn, opts) do
{:ok, body, conn} = Plug.Conn.read_body(conn, opts)
conn = update_in(conn.assigns[:raw_body], &[body | (&1 || [])])
case Plug.Conn.get_req_header(conn, "content-encoding") do
["gzip"] ->
deflated = :zlib.gunzip(body)
{:ok, deflated, conn}
_ ->
{:ok, body, conn}
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.