cowboy_middleware.asciidoc 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. = cowboy_middleware(3)
  2. == Name
  3. cowboy_middleware - behaviour for middlewares
  4. == Description
  5. The `cowboy_middleware` behaviour defines the interface used
  6. by Cowboy middleware modules.
  7. Middlewares process the request sequentially in the order they
  8. are configured.
  9. == Types
  10. === env() = [{atom(), any()}]
  11. The environment variable.
  12. One is created for every request. It is passed to each
  13. middleware module executed and subsequently returned,
  14. optionally with its contents modified.
  15. == Callbacks
  16. === execute(Req, Env) -> {ok, Req, Env} | {suspend, Module, Function, Args} | {stop, Req}
  17. Req = cowboy_req:req():: The Req object.
  18. Env = env():: The request environment.
  19. Module = module():: MFA to call when resuming the process.
  20. Function = atom():: MFA to call when resuming the process.
  21. Args = [any()]:: MFA to call when resuming the process.
  22. Execute the middleware.
  23. The `ok` return value indicates that everything went well
  24. and that Cowboy should continue processing the request. A
  25. response may or may not have been sent.
  26. The `suspend` return value will hibernate the process until
  27. an Erlang message is received. Note that when resuming, any
  28. previous stacktrace information will be gone.
  29. The `stop` return value stops Cowboy from doing any further
  30. processing of the request, even if there are middlewares
  31. that haven't been executed yet. The connection may be left
  32. open to receive more requests from the client.