MuroPlug.Handler (muro_plug v0.1.0)

Copy Markdown View Source

The Thousand Island handler that drives the emitted step.muro.

Each socket event is one book fact: accept, bytes, wrote, now. The book's Out says what to do next and the handler does only that:

  • read more (book phases 0, 4, 7),
  • write an owed protocol status and close (phase 1: 400, 413, 414, 417, 431, 501, or a status_now close),
  • write the 100 Continue interim (span 6) and feed the wrote back,
  • serve a finished request through the Plug (phase 3, span 2), then feed the wrote so the book either closes, idles, or classifies a pipelined tail in the same step,
  • close (phases 2 and 5, or cover).

The receive buffer is one binary. Request views, framing ends and header-block ends all come from the book.

A Plug that upgrades to WebSocket (Plug.Conn.upgrade_adapter/3 with :websocket, e.g. through WebSockAdapter.upgrade/4) leaves the book here: once the Plug returns, the handler writes the 101 Switching Protocols and the connection becomes a MuroPlug.WebSocket.Connection. Any bytes after the upgrade request are its first frame bytes. Process messages go to the WebSock module's handle_info/2.

The handler is the same over TCP and TLS: Thousand Island finishes the TLS handshake before handle_connection/2, and every read and write goes through ThousandIsland.Socket. The scheme ("http" or "https") comes from MuroPlug's options.

Summary

Functions

Returns a specification to start this module under a supervisor.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

start_link(arg)

@spec start_link({handler_options :: term(), GenServer.options()}) ::
  GenServer.on_start()