MuroPlug (muro_plug v0.1.0)

Copy Markdown View Source

A Plug and Phoenix adapter that serves HTTP/1.1 from the muro-http book.

priv/muro/http/step.muro (and the request.muro it imports) are pinned copies of the muro-http books. mix muro.gen emits them with muro's default Elixir backend into MuroPlug.Step. The Thousand Island handler (MuroPlug.Handler) feeds every socket event to that emitted step as a fact and does what the step's Out says. The Plug.Conn.Adapter (MuroPlug.Adapter) asks the same book how to frame each response. Octets stay binaries on the BEAM.

Usage

children = [
  {MuroPlug, plug: MyApp.Router, port: 4000}
]

HTTPS, over ThousandIsland.Transports.SSL:

children = [
  {MuroPlug,
   plug: MyApp.Router,
   scheme: :https,
   port: 4040,
   certfile: "/etc/my_app/cert.pem",
   keyfile: "/etc/my_app/key.pem"}
]

Options:

  • :plug — a Plug module or {module, opts}. Required.
  • :scheme — :http (the default) or :https.
  • :port — listen port. Defaults to 4000 for :http and 4040 for :https; 0 lets the OS pick.
  • :ip — listen address tuple. Defaults to all interfaces.
  • :max_body — the book's max: a Content-Length or chunked total past this is 413. Defaults to 8_000_000.
  • :idle_timeout — the book's idle budget in milliseconds, and the Thousand Island read timeout. Defaults to 60_000.
  • :thousand_island_options — passed to ThousandIsland. Its :transport_options go to the transport (:gen_tcp or :ssl).

With scheme: :https these TLS options are passed to :ssl after Plug.SSL.configure/1, the same checks Plug.Cowboy and Bandit run: :keyfile, :certfile, :cacertfile, :dhfile, :key, :cert, :cacerts, :certs_keys, :sni_hosts, :sni_fun, :password, :otp_app (relative file paths resolve against its app dir), :cipher_suite (:strong or :compatible), :ciphers, :versions, :eccs, :verify, :fail_if_no_peer_cert, and :alpn_preferred_protocols. A key and a certificate (or :certs_keys, or SNI) are required. The server speaks HTTP/1.1 only, so ALPN advertises "http/1.1" and no other protocol may be listed.

TLS options may also sit in thousand_island_options: [transport_options: ...]; top-level ones win. :ssl is started before the listener.

An invalid :scheme, missing TLS key or certificate, or TLS options given with scheme: :http (top-level or in :transport_options) raise ArgumentError.

WebSocket upgrades (ws:// over :http, wss:// over :https) go through the WebSock API; see MuroPlug.WebSocket.

For Phoenix, see MuroPlug.PhoenixAdapter.

Summary

Functions

A child spec for a MuroPlug server.

Start a MuroPlug server linked to the caller.

Functions

child_spec(opts)

@spec child_spec(keyword()) :: Supervisor.child_spec()

A child spec for a MuroPlug server.

start_link(opts)

@spec start_link(keyword()) :: Supervisor.on_start()

Start a MuroPlug server linked to the caller.