title: Validating headers for specific endpoints with Plug
body: <h2>Background</h2>
  <p>I have a simple Plug router that has some POST, PUT and GET endpoints. However, each endpoint needs to make a specific validation on the headers of the request. I don’t know how to achieve this with Plug.
  Code</p>
  <p>I have a very generic router that receives requests and redirects them to controllers:</p>
  <pre><code>defmodule Api do
    use Plug.Router
  
    alias Api.Controllers.{Product, NotFound, Ping}
  
    plug :match
    plug Plug.Logger
    plug :dispatch
  
    get &quot;/ping&quot;,  do: Ping.process(conn)
    put &quot;/product&quot;,    do: Product.process(conn)
  
    match _, do: NotFound.process(conn)
  end
  </code></pre>
  <h2>Issue</h2>
  <p>However, there is a step missing. I need for the /products endpoint to validate the headers. Namely the headers should have some specific fields set, for example, like the “conten-type” header or even a custom header like “bananas”.</p>
  <p>This validation is NOT for all endpoints. What makes it worse is that each endpoint will make its own validations, for example, having a “bananas” header may be important for the “/products” endpoint, but the “/ping” endpoint doesn’t really care.</p>
  <h2>Research</h2>
  <p>I have read this article:</p>
  <ul>
  <li><a href="https://www.adamconrad.dev/blog/verifying-request-signatures-in-elixir-phoenix/" rel="nofollow noreferrer">https://www.adamconrad.dev/blog/verifying-request-signatures-in-elixir-phoenix/</a></li>
  </ul>
  <p>However, this applies to all endpoints and is not specific.</p>
  <h2>Questions</h2>
  <ul>
  <li>Is it possible to achieve what I am looking for with Plug? If so, how?</li>
  </ul>