From c08678c66daae6879ab9e4180573f8d8fa0d58ff Mon Sep 17 00:00:00 2001 From: agustin2606 Date: Tue, 24 Nov 2026 16:13:04 -0300 Subject: [PATCH] Document that Plug.Parsers does not reject QUERY without content-type --- lib/plug/parsers.ex | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/plug/parsers.ex b/lib/plug/parsers.ex index 6246526e9..c771a15df 100644 --- a/lib/plug/parsers.ex +++ b/lib/plug/parsers.ex @@ -79,6 +79,24 @@ defmodule Plug.Parsers do For requests with a different request method, this plug will only fetch the query params. + If the request has no `content-type` header, the body is not read and + `:body_params` is set to an empty map. RFC 10008 requires servers to + reject a `QUERY` request without a `content-type`, which this plug does + not do, as it cannot know how the body is going to be used (for example, + when it is passed through). Applications accepting `QUERY` requests should + check it themselves, for example with a plug placed before `Plug.Parsers`: + + plug :require_query_content_type + + defp require_query_content_type(%{method: "QUERY"} = conn, _opts) do + case get_req_header(conn, "content-type") do + [] -> conn |> send_resp(415, "") |> halt() + _ -> conn + end + end + + defp require_query_content_type(conn, _opts), do: conn + ## Options * `:parsers` - a list of modules or atoms of built-in parsers to be