Created
February 23, 2018 16:50
-
-
Save atomkirk/e05fbab86f34331ffe812a1b98f63851 to your computer and use it in GitHub Desktop.
raw body plug parser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plug Plug.Parsers, | |
parsers: [ZB.Parsers.RAWBODY, :urlencoded, :multipart, :json], | |
pass: ["*/*"], | |
json_decoder: Poison |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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