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 HandlerError {
InvalidRequest(DecodeError)
NotFound
}
Constructors
-
InvalidRequest(DecodeError)
-
NotFound
pub type HandlerFunc =
fn(Request(BitString)) -> HandlerResponse
pub type HandlerResponse {
Response(response: response.Response(HttpResponseBody))
Upgrade(with_handler: websocket.Handler)
}
Constructors
-
Response(response: response.Response(HttpResponseBody))
-
Upgrade(with_handler: websocket.Handler)
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 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 PacketType {
Http
HttphBin
HttpBin
}
Constructors
-
Http
-
HttphBin
-
HttpBin
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 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,
)