MuroPlug.Book (muro_plug v0.1.0)

Copy Markdown View Source

A thin, total reading of the emitted step.muro (MuroPlug.Step).

The book decides every protocol fact of one HTTP/1.1 connection: when a request is complete, where it ends, whether it keeps the connection, which protocol status (400, 413, 414, 417, 431, 501) is owed, when a 100 Continue interim is owed, and how a handler response is framed. This module only names the fields of the book's Out and St products and feeds it facts. It does not make protocol decisions of its own.

The buffer passed to the book is always a binary (Slice on the BEAM). Nothing here builds a list of octets.

Summary

Types

The book's Out product, decoded by out/1.

The book's St: {:st, phase, code, left, keep, hend, te, sawCL, cl}.

Functions

True when the chunked body after hend is finished in buf (ckDone).

First byte past the request this Out describes (framedEndAt).

Feed the handler's result to the book (hand in step.muro).

Decode the book's Out tuple into a map.

The protocol span a failed body read owes after a successful handler (overStatus in step.muro): 400 or 413 owes that status and closes; any other code is outside (cover 1), and the host shuts.

The book's initial read state.

Feed one fact to the book. fact is an atom; buf the unconsumed buffer.

The book's St for an Out (take in step.muro).

Request-line views over the buffer.

Types

out()

@type out() :: %{
  raw: tuple(),
  phase: non_neg_integer(),
  code: non_neg_integer(),
  close: 0 | 1,
  status_now: 0 | 1,
  read_more: 0 | 1,
  write_more: 0 | 1,
  span: non_neg_integer(),
  cover: 0 | 1,
  left: non_neg_integer(),
  wake: non_neg_integer(),
  keep: 0 | 1,
  hend: non_neg_integer(),
  te: non_neg_integer(),
  saw_cl: non_neg_integer(),
  cl: non_neg_integer()
}

The book's Out product, decoded by out/1.

st()

@type st() :: tuple()

The book's St: {:st, phase, code, left, keep, hend, te, sawCL, cl}.

Functions

chunk_done?(map, buf)

@spec chunk_done?(out(), binary()) :: boolean()

True when the chunked body after hend is finished in buf (ckDone).

framed_end(o, buf)

@spec framed_end(out(), binary()) :: non_neg_integer()

First byte past the request this Out describes (framedEndAt).

hand(req, flags)

@spec hand(out(), keyword()) :: out()

Feed the handler's result to the book (hand in step.muro).

Returns the framing the book chose: span 2 is a buffered body, 3 a content-length pull (send_file), 4 chunked, 5 close-delimited; keep 0 keeps the connection, 1 closes it.

out(raw)

@spec out(tuple()) :: out()

Decode the book's Out tuple into a map.

over_status(req, code)

@spec over_status(out(), non_neg_integer()) :: out()

The protocol span a failed body read owes after a successful handler (overStatus in step.muro): 400 or 413 owes that status and closes; any other code is outside (cover 1), and the host shuts.

read_st()

@spec read_st() :: st()

The book's initial read state.

step(st, fact, buf, cfg, n \\ 0, owed \\ 0)

@spec step(st(), atom(), binary(), map(), non_neg_integer(), non_neg_integer()) ::
  out()

Feed one fact to the book. fact is an atom; buf the unconsumed buffer.

The carried deadline is always 0, so the book arms now + idle on each read. Thousand Island's read_timeout is that same idle budget and delivers the NOW fact (MuroPlug.Handler.handle_timeout/2), so the book's wake is not re-armed by the host.

take(map)

@spec take(out()) :: st()

The book's St for an Out (take in step.muro).

views(buf)

@spec views(binary()) :: %{
  method: binary(),
  target: binary(),
  path: binary(),
  query: binary(),
  version: binary()
}

Request-line views over the buffer.