Bandit (Bandit v0.3.9) View Source

Defines a Bandit server as part of a supervision tree. A typical child spec to start a Bandit server hosting a plug looks like:

{Bandit, plug: {MyApp.Plug, :arg_passed_to_plug_init}, options: [port: 4000]}

Three options are supported:

  • scheme: One of :http or :https. If :https is supported, you will need to specify certfile and keyfile in the transport_options subsection of options.
  • plug: The plug to handle connections. Can be specified as MyPlug or {MyPlug, plug_opts}
  • read_timeout: How long to wait for data from the client before timing out and closing the connection, specified in milliseconds. Defaults to 60_000
  • options: Options to pass to ThousandIsland. For an exhaustive list of options see the ThousandIsland documentation, however some common options are:
    • port: The port to bind to. Defaults to 4000
    • num_acceptors: The number of acceptor processes to run. This is mostly a performance tuning knob and can usually be left at the default value of 10
    • transport_module: The name of the module which provides basic socket functions. This overrides any value set for scheme and is intended for cases where control over the socket at a fundamental level is needed.
    • transport_options: A keyword list of options to be passed into the transport socket's listen function

Link to this section Summary

Types

A Plug definition

Link to this section Types

Specs

plug() :: {module(), keyword()}

A Plug definition

Link to this section Functions

Specs

child_spec([]) :: Supervisor.child_spec()