Skip to content

Instantly share code, notes, and snippets.

@atomkirk
Created February 23, 2018 16:50
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atomkirk/e05fbab86f34331ffe812a1b98f63851 to your computer and use it in GitHub Desktop.
Save atomkirk/e05fbab86f34331ffe812a1b98f63851 to your computer and use it in GitHub Desktop.
raw body plug parser
plug Plug.Parsers,
parsers: [ZB.Parsers.RAWBODY, :urlencoded, :multipart, :json],
pass: ["*/*"],
json_decoder: Poison
defmodule ZB.Parsers.RAWBODY do
@behaviour Plug.Parsers
alias Plug.Conn
def parse(%{request_path: "/v2/subscriptions/stripe-webhook"} = conn, _type, _subtype, _headers, opts) do
do_parse(conn, opts)
end
def parse(conn, _type, _subtype, _headers, _opts) do
{:next, conn}
end
defp do_parse(conn, opts) do
case Conn.read_body(conn, opts) do
{:ok, body, conn} ->
{:ok, %{raw: body}, conn}
{:more, _data, conn} ->
{:error, :too_large, conn}
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment