cowboy.asciidoc 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. = cowboy(3)
  2. == Name
  3. cowboy - HTTP server
  4. == Description
  5. The `cowboy` module provides convenience functions for
  6. manipulating Ranch listeners.
  7. == Types
  8. === fields() = [Field]
  9. [source,erlang]
  10. ----
  11. Field = atom()
  12. | {atom(), cowboy_constraints:constraint() | [cowboy_constraints:constraint()]}
  13. | {atom(), cowboy_constraints:constraint() | [cowboy_constraints:constraint()], any()}]
  14. ----
  15. Fields for match operations. Constraint(s) and default value are optional.
  16. === http_headers() = [{binary(), iodata()}]
  17. HTTP headers as a list of key/values.
  18. === http_status() = non_neg_integer() | binary()
  19. HTTP status.
  20. A binary status can be used to set a custom message.
  21. === http_version() = \'HTTP/1.1' | \'HTTP/1.0'
  22. HTTP version.
  23. === `onresponse_fun() = fun((http_status(), http_headers(), 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. Ref = ranch:ref():: Listener name.
  32. NbAcceptors = non_neg_integer():: Number of acceptor processes.
  33. TransOpts = ranch_tcp:opts():: TCP transport options.
  34. ProtoOpts = cowboy_protocol:opts():: HTTP protocol options.
  35. Start listening for HTTP connections. Returns the pid for this
  36. listener's supervisor.
  37. === start_https(Ref, NbAcceptors, TransOpts, ProtoOpts) -> {ok, pid()}
  38. Ref = ranch:ref():: Listener name.
  39. NbAcceptors = non_neg_integer():: Number of acceptor processes.
  40. TransOpts = ranch_ssl:opts():: SSL transport options.
  41. ProtoOpts = cowboy_protocol:opts():: HTTP protocol options.
  42. Start listening for HTTPS connections. Returns the pid for this
  43. listener's supervisor.
  44. === stop_listener(Ref) -> ok | {error, not_found}
  45. Ref = ranch:ref():: Listener name.
  46. Stop a previously started listener.
  47. === set_env(Ref, Name, Value) -> ok
  48. Ref = ranch:ref():: Listener name.
  49. Name = atom():: Name of environment value.
  50. Value = any():: Environment value.
  51. Set or update an environment value for an already running listener.
  52. This will take effect on all subsequent connections.
  53. == See also
  54. The http://ninenines.eu/docs/en/ranch/HEAD/guide[Ranch guide]
  55. provides detailed information about how listeners work.