mist/internal/http

Types

pub type Body {
  Initial(BitArray)
  Stream(
    selector: process.Selector(#(BitArray, Bool)),
    data: BitArray,
    end: Bool,
    attempts: Int,
    send_headers: fn(Int, List(#(String, String))) -> Nil,
    send_data: fn(BitArray) -> Result(Nil, Nil),
    consume_data: fn(Int) -> Nil,
    close_after: fn(process.Pid) -> Nil,
  )
}

Constructors

  • Initial(BitArray)
  • Stream(
      selector: process.Selector(#(BitArray, Bool)),
      data: BitArray,
      end: Bool,
      attempts: Int,
      send_headers: fn(Int, List(#(String, String))) -> Nil,
      send_data: fn(BitArray) -> Result(Nil, Nil),
      consume_data: fn(Int) -> Nil,
      close_after: fn(process.Pid) -> Nil,
    )
pub type Chunk {
  Chunk(data: BitArray, buffer: buffer.Buffer)
  Complete
}

Constructors

pub type ChunkProcess {
  ChunkProcessStarted
  ChunkProcessStopped(process.ExitReason)
}

Constructors

pub type Connection {
  Connection(
    body: Body,
    socket: socket.Socket,
    transport: transport.Transport,
    factory_name: process.Name(
      factory_supervisor.Message(
        fn() -> Result(
          actor.Started(process.Pid),
          actor.StartError,
        ),
        process.Pid,
      ),
    ),
    read_timeout: Int,
    chunk_process: process.Subject(ChunkProcess),
  )
}

Constructors

pub type DecodeError {
  MalformedRequest
  InvalidMethod
  InvalidPath
  UnknownHeader
  UnknownMethod
  InvalidBody
  ExcessBody
  DiscardPacket
  NoHostHeader
  InvalidHttpVersion
}

Constructors

  • MalformedRequest
  • InvalidMethod
  • InvalidPath
  • UnknownHeader
  • UnknownMethod
  • InvalidBody
  • ExcessBody
  • DiscardPacket
  • NoHostHeader
  • InvalidHttpVersion
pub type DecodedPacket {
  BinaryData(HttpPacket, BitArray)
  EndOfHeaders(BitArray)
  MoreData(option.Option(Int))
  Http2Upgrade(BitArray)
}

Constructors

pub type HttpPacket {
  HttpRequest(dynamic.Dynamic, HttpUri, #(Int, Int))
  HttpHeader(Int, atom.Atom, BitArray, BitArray)
}

Constructors

pub type HttpUri {
  AbsPath(BitArray)
}

Constructors

  • AbsPath(BitArray)
pub type HttpVersion {
  Http1
  Http11
}

Constructors

  • Http1
  • Http11
pub type PacketType {
  Http
  HttphBin
  HttpBin
}

Constructors

  • Http
  • HttphBin
  • HttpBin
pub type ParsedRequest {
  Http1Request(
    request: request.Request(Connection),
    version: HttpVersion,
  )
  Upgrade(BitArray)
}

Constructors

pub type ResponseData {
  Websocket
  Bytes(bytes_tree.BytesTree)
  Chunked
  File(descriptor: file.FileDescriptor, offset: Int, length: Int)
  ServerSentEvents
}

Constructors

pub type ShaHash {
  Sha
}

Constructors

  • Sha

Values

pub fn add_content_length(
  when when: Bool,
  length length: Int,
) -> fn(response.Response(any)) -> response.Response(any)
pub fn add_date_header(
  resp: response.Response(any),
) -> response.Response(any)
pub fn add_default_headers(
  resp: response.Response(bytes_tree.BytesTree),
  is_head_response: Bool,
) -> response.Response(bytes_tree.BytesTree)
pub fn base64_encode(data data: String) -> String
pub fn close_if_requested(
  req: request.Request(any),
  resp: response.Response(body),
) -> response.Response(body)
pub fn connection_close(
  resp: response.Response(any),
) -> response.Response(any)
pub fn crypto_hash(
  hash hash: ShaHash,
  data data: String,
) -> String
pub fn from_header(value: BitArray) -> String
pub fn handle_continue(
  req: request.Request(Connection),
) -> Result(Nil, DecodeError)
pub fn keep_alive(
  resp: response.Response(any),
) -> response.Response(any)
pub fn maybe_keep_alive(
  resp: response.Response(any),
) -> response.Response(any)
pub fn parse_chunk(string: BitArray) -> Chunk
pub fn parse_headers(
  bs: BitArray,
  socket: socket.Socket,
  transport: transport.Transport,
  headers: dict.Dict(String, String),
  read_timeout: Int,
) -> Result(#(dict.Dict(String, String), BitArray), DecodeError)
pub fn parse_request(
  bs: BitArray,
  conn: Connection,
) -> Result(ParsedRequest, DecodeError)

Turns the TCP message into an HTTP request

pub fn read_body(
  req: request.Request(Connection),
  max_body_limit: Int,
) -> Result(request.Request(BitArray), DecodeError)
pub fn read_data(
  socket: socket.Socket,
  transport: transport.Transport,
  buffer: buffer.Buffer,
  error: DecodeError,
  read_timeout: Int,
) -> Result(BitArray, DecodeError)
pub fn upgrade(
  socket: socket.Socket,
  transport: transport.Transport,
  extensions: List(String),
  req: request.Request(Connection),
) -> Result(Nil, Nil)
pub fn upgrade_socket(
  req: request.Request(Connection),
  extensions: List(String),
) -> Result(
  response.Response(bytes_tree.BytesTree),
  request.Request(Connection),
)
pub fn version_to_string(version: HttpVersion) -> String
pub fn watch_chunk_process(conn: Connection) -> Nil

Run this in the process that sends the body, before it handles its first message. Another process then watches it, and tells the connection how it stopped. The watcher is there before this process can stop, so it also sees a process that stops at once

✨ Search Document