howdy/content

What a response carries. Handlers return Response(Content), usually built with controller.text, controller.json and friends.

response.new(200)
|> response.set_header("content-type", "text/csv")
|> response.set_body(content.Text(csv))

Types

The body of a response.

pub type Content {
  Text(String)
  Bytes(bytes_tree.BytesTree)
  Empty
  Native(Native)
}

Constructors

  • Text(String)

    Text, sent as UTF-8.

  • Raw bytes.

  • Empty

    No body at all.

  • Native(Native)

    A body only the server can send, such as a file from howdy/static, a socket upgrade from howdy/websocket, a stream from howdy/sse or a body written in chunks by howdy/stream. It cannot be built or read directly; middleware should pass it through unchanged.

See Native on Content.

pub opaque type Native

Why something could not be sent on an open connection: a WebSocket frame, a server-sent event, or a chunk of a streamed body.

pub type SendError {
  ConnectionClosed
  StreamReset
  SendTimedOut
  SocketError(reason: String)
}

Constructors

  • ConnectionClosed

    The client is gone, so nothing further can be written.

  • StreamReset

    The client cancelled the HTTP/2 stream the response runs on.

  • SendTimedOut

    The client stopped reading for long enough that the write gave up.

  • SocketError(reason: String)

    The socket refused the write for another reason, described by reason.

✨ Search Document