cowboy.ezdoc 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. ::: cowboy
  2. The `cowboy` module provides convenience functions for
  3. manipulating Ranch listeners.
  4. :: Types
  5. : fields() = [atom()
  6. | {atom(), cowboy_constraints:constraint() | [cowboy_constraints:constraint()]}
  7. | {atom(), cowboy_constraints:constraint() | [cowboy_constraints:constraint()], any()}]
  8. Fields for match operations. Constraint(s) and default value are optional.
  9. : http_headers() = [{binary(), iodata()}]
  10. HTTP headers as a list of key/values.
  11. : http_status() = non_neg_integer() | binary()
  12. HTTP status.
  13. A binary status can be used to set a custom message.
  14. : http_version() = 'HTTP/1.1' | 'HTTP/1.0'
  15. HTTP version.
  16. : onrequest_fun() = fun((cowboy_req:req()) -> cowboy_req:req())
  17. Fun called immediately after receiving a request.
  18. It can perform any operation on the Req object, including
  19. reading the request body or replying. If a reply is sent,
  20. the processing of the request ends here, before any middleware
  21. is executed.
  22. : onresponse_fun() = fun((http_status(), http_headers(),
  23. iodata(), cowboy_req:req()) -> cowboy_req:req())
  24. Fun called immediately before sending the response.
  25. It can perform any operation on the Req object, including
  26. reading the request body or replying. If a reply is sent, it
  27. overrides the reply initially sent. The callback will not be
  28. called again for the new reply.
  29. :: Exports
  30. : start_http(Ref, NbAcceptors, TransOpts, ProtoOpts) -> {ok, pid()}
  31. Types:
  32. * Ref = ranch:ref()
  33. * NbAcceptors = non_neg_integer()
  34. * TransOpts = ranch_tcp:opts()
  35. * ProtoOpts = cowboy_protocol:opts()
  36. Start listening for HTTP connections. Returns the pid for this
  37. listener's supervisor.
  38. : start_https(Ref, NbAcceptors, TransOpts, ProtoOpts) -> {ok, pid()}
  39. Types:
  40. * Ref = ranch:ref()
  41. * NbAcceptors = non_neg_integer()
  42. * TransOpts = ranch_ssl:opts()
  43. * ProtoOpts = cowboy_protocol:opts()
  44. Start listening for HTTPS connections. Returns the pid for this
  45. listener's supervisor.
  46. : start_spdy(Ref, NbAcceptors, TransOpts, ProtoOpts) -> {ok, pid()}
  47. Types:
  48. * Ref = ranch:ref()
  49. * NbAcceptors = non_neg_integer()
  50. * TransOpts = ranch_ssl:opts()
  51. * ProtoOpts = cowboy_spdy:opts()
  52. Start listening for SPDY connections. Returns the pid for this
  53. listener's supervisor.
  54. : stop_listener(Ref) -> ok | {error, not_found}
  55. Types:
  56. * Ref = ranch:ref()
  57. Stop a previously started listener.
  58. : set_env(Ref, Name, Value) -> ok
  59. Types:
  60. * Ref = ranch:ref()
  61. * Name = atom()
  62. * Value = any()
  63. Set or update an environment value for an already running listener.
  64. This will take effect on all subsequent connections.
  65. :: See also
  66. The ^"Ranch guide^http://ninenines.eu/docs/en/ranch/HEAD/guide
  67. provides detailed information about how listeners work.