mist/http

Types

pub type DecodeError {
  InvalidMethod
  InvalidPath
  UnknownHeader
}

Constructors

  • InvalidMethod
  • InvalidPath
  • UnknownHeader
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(BitString)
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 from_header(value: BitString) -> String
pub fn handler(func: fn(Request(BitString)) ->
    Response(BitString)) -> fn(HandlerMessage, #(Socket, Nil)) ->
  Next(#(Socket, Nil))

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

pub fn headers(resp: Response(BitString)) -> StringBuilder
pub fn parse_headers(bs: BitString, headers: List(
    #(String, String),
  )) -> Result(#(List(#(String, String)), BitString), DecodeError)
pub fn parse_request(bs: BitString) -> Result(
  Request(BitString),
  DecodeError,
)

Turns the TCP message into an HTTP request

pub fn status_to_bit_string(status: Int) -> BitString
pub fn to_bit_builder(resp: Response(BitString)) -> BitBuilder

Turns an HTTP response into a TCP message