mist/http

Types

pub type Buffer {
  Buffer(remaining: Int, data: BitString)
}

Constructors

  • Buffer(remaining: Int, data: BitString)
pub type DecodeError {
  InvalidMethod
  InvalidPath
  UnknownHeader
  UnknownMethod
  InvalidBody
}

Constructors

  • InvalidMethod
  • InvalidPath
  • UnknownHeader
  • UnknownMethod
  • InvalidBody
pub type DecodedPacket {
  BinaryData(HttpPacket, BitString)
  EndOfHeaders(BitString)
  MoreData(Option(Int))
}

Constructors

  • BinaryData(HttpPacket, BitString)
  • EndOfHeaders(BitString)
  • MoreData(Option(Int))
pub type Handler =
  fn(request.Request(BitString)) -> response.Response(BitBuilder)
pub type HandlerError {
  InvalidRequest(DecodeError)
  NotFound
}

Constructors

  • InvalidRequest(DecodeError)
  • NotFound
pub type HandlerFunc =
  fn(Request(BitString)) -> HandlerResponse
pub type HandlerResponse {
  Response(response: response.Response(HttpResponseBody))
  Upgrade(websocket.WebsocketHandler)
}

Constructors

  • Response(response: response.Response(HttpResponseBody))
  • Upgrade(websocket.WebsocketHandler)
pub type HttpPacket {
  HttpRequest(Dynamic, HttpUri, #(Int, Int))
  HttpHeader(Int, Atom, BitString, BitString)
}

Constructors

  • HttpRequest(Dynamic, HttpUri, #(Int, Int))
  • HttpHeader(Int, Atom, BitString, BitString)
pub type HttpResponseBody {
  BitBuilderBody(BitBuilder)
  FileBody(
    file_descriptor: file.FileDescriptor,
    content_type: String,
    offset: Int,
    length: Int,
  )
}

Constructors

  • BitBuilderBody(BitBuilder)
  • FileBody(
      file_descriptor: file.FileDescriptor,
      content_type: String,
      offset: Int,
      length: Int,
    )
pub type HttpUri {
  AbsPath(BitString)
}

Constructors

  • AbsPath(BitString)
pub type PacketType {
  Http
  HttphBin
  HttpBin
}

Constructors

  • Http
  • HttphBin
  • HttpBin
pub type State {
  State(
    idle_timer: Option(process.Timer),
    upgraded_handler: Option(websocket.WebsocketHandler),
  )
}

Constructors

  • State(
      idle_timer: Option(process.Timer),
      upgraded_handler: Option(websocket.WebsocketHandler),
    )

Functions

pub fn from_header(value: BitString) -> String
pub fn handler(handler: fn(Request(BitString)) ->
    Response(BitBuilder)) -> fn(HandlerMessage, LoopState(State)) ->
  Next(LoopState(State))

Creates a standard HTTP handler service to pass to mist.serve

pub fn handler_func(handler: fn(Request(BitString)) ->
    HandlerResponse) -> fn(HandlerMessage, LoopState(State)) ->
  Next(LoopState(State))

This is a more flexible handler. It will allow you to upgrade a connection to a websocket connection, or deal with a regular HTTP req->resp workflow.

pub fn new_state() -> State
pub fn parse_headers(bs: BitString, socket: Socket, headers: Map(
    String,
    String,
  )) -> Result(#(Map(String, String), BitString), DecodeError)
pub fn parse_request(bs: BitString, socket: Socket) -> Result(
  Request(BitString),
  DecodeError,
)
pub fn read_data(socket: Socket, buffer: Buffer, error: DecodeError) -> Result(
  BitString,
  DecodeError,
)