PhoenixApiToolkit.Security.Plugs.require_content_type

You're seeing just the function require_content_type, go back to PhoenixApiToolkit.Security.Plugs module for more information.
Link to this function

require_content_type(conn, arg2 \\ nil)

View Source

Specs

require_content_type(Plug.Conn.t(), Plug.opts()) :: Plug.Conn.t()

Checks if the request's "content-type" header is present. Content matching is done by Plug.Parsers.

The filter is only applied to methods which are expected to carry contents, to PUT, POST and PATCH methods, that is. Only one content-type header is allowed. A noncompliant request causes a PhoenixApiToolkit.Security.MissingContentTypeError to be raised, resulting in a 415 Unsupported Media Type response.

Examples

use Plug.Test

# safe methods pass through
iex> conn = conn(:get, "/")
iex> conn == require_content_type(conn)
true

# compliant unsafe methods (put, post and patch) pass through
iex> conn = conn(:post, "/") |> put_req_header("content-type", "application/json")
iex> conn == require_content_type(conn)
true

# noncompliant unsafe methods cause a MissingContentTypeError to be raised
iex> conn(:post, "/") |> require_content_type()
** (PhoenixApiToolkit.Security.MissingContentTypeError) missing 'content-type' header