Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions lib/lightning_web/plug_configs.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,22 @@ defmodule LightningWeb.PlugConfigs do
}
],
pass: ["*/*"],
body_reader: {__MODULE__, :decompress_body, []},
json_decoder: Phoenix.json_library()
]
end

@doc """
Custom body reader that decompresses gzipped request bodies.
"""
def decompress_body(conn, opts) do
case Plug.Conn.get_req_header(conn, "content-encoding") do
["gzip" | _] ->
{:ok, body, conn} = Plug.Conn.read_body(conn, opts)
{:ok, :zlib.gunzip(body), conn}

_ ->
Plug.Conn.read_body(conn, opts)
end
end
end