mist/http

Types

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

Constructors

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

Constructors

  • InvalidMethod
  • InvalidPath
  • UnknownHeader
  • 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(BitBuilder)
pub type HandlerError {
  InvalidRequest(DecodeError)
  NotFound
}

Constructors

  • InvalidRequest(DecodeError)
  • NotFound
pub type HttpPacket {
  HttpRequest(Atom, HttpUri, #(Int, Int))
  HttpHeader(Int, Atom, BitString, BitString)
}

Constructors

  • HttpRequest(Atom, HttpUri, #(Int, Int))
  • HttpHeader(Int, Atom, BitString, BitString)
pub type HttpUri {
  AbsPath(BitString)
}

Constructors

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

Constructors

  • Http
  • HttphBin
  • HttpBin

Functions

pub fn encode_headers(headers: Map(String, String)) -> BitBuilder
pub fn from_header(value: BitString) -> String
pub fn handler(func: fn(Request(BitString)) ->
    Response(BitBuilder)) -> fn(
  HandlerMessage,
  LoopState(Option(Timer)),
) -> Next(LoopState(Option(Timer)))

This method helps turn an HTTP handler into a TCP handler that you can pass to mist.serve or glisten.serve

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,
)

Turns the TCP message into an HTTP request

pub fn read_data(socket: Socket, buffer: Buffer, error: DecodeError) -> Result(
  BitString,
  DecodeError,
)
pub fn status_to_bit_string(status: Int) -> BitString
pub fn to_bit_builder(resp: Response(BitBuilder)) -> BitBuilder

Turns an HTTP response into a TCP message