execute(Req, Env) -> {ok, Req, Env} | {suspend, module(), atom(), [any()]} | {stop, Req} Req :: cowboy_req:req() Env :: cowboy_middleware:env()
cowboy_middleware - Middlewares
The module cowboy_middleware
defines a callback interface for Cowboy middlewares.
Middlewares process the request sequentially in the order they are configured.
Middlewares implement the following interface:
execute(Req, Env) -> {ok, Req, Env} | {suspend, module(), atom(), [any()]} | {stop, Req} Req :: cowboy_req:req() Env :: cowboy_middleware:env()
The execute/2
is the only callback that needs to be implemented. It must execute the middleware and return with instructions for Cowboy.
Cowboy should continue processing the request using the returned Req object and environment.
Cowboy will hibernate the process. When resuming, Cowboy will apply the returned module, function and arguments.
Cowboy will stop middleware execution. No other middleware will be executed. This effectively ends the processing of the request.
env() :: #{atom() => any()}
Middleware environment.
A new environment is created for every request. The initial environment contained the user configured environment values (like dispatch
for example) plus the listener
value which contains the name of the listener for this connection.
Middlewares may modify the environment as necessary.
env
type is now a map instead of a proplist.
Donate to Loïc Hoguin because his work on Cowboy, Ranch, Gun and Erlang.mk is fantastic:
Recurring payment options are also available via GitHub Sponsors. These funds are used to cover the recurring expenses like food, dedicated servers or domain names.