elixir-plug / plug

Compose web applications with functions
https://hex.pm/packages/plug
Other
2.81k stars 578 forks source link

Docs inconsistency between Plug moduledoc and Plug.run #1201

Closed wojtekmach closed 6 months ago

wojtekmach commented 6 months ago

In Plug moduledoc we have:

A function plug is any function that receives a connection and a set of options and returns a connection. Its type signature must be:

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

however in Plug.run doc we have:

(...) (Plug.Conn.t -> Plug.conn.t()) (...)

The plugs given here can be either a tuple, representing a module plug and their options, or a simple function that receives a connection and returns a connection.

I'm not sure how, if at all, solve this inconsistency given the vast majority of plugs are modules with call/2 and functions called by plug macro which then need to be of arity 2.

josevalim commented 6 months ago

The arity/1 makes sense from Plug.run/1 point of view, there are no options to pass around, so they have to be captured inside arity/1 functions. I don't think it is part of the Plug contract, so I don't think Bandit should support it because of Plug (it is their own call).

You can always have {Plug.Call, &fun/1} though and pass that to Bandit.