Module Naboris.Res
Module for creating and sending responses.
val default : unit -> t
Creates a default response record with empty headers and a 200 status.
val json : 'sessionData Req.t -> string -> t -> t Lwt.t
Sends response
t
with bodystring
. Adding headersContent-type: application/json
andContent-length
This function will end the http request/response lifecycle.
val html : 'sessionData Req.t -> string -> t -> t Lwt.t
Sends response
t
with bodystring
. Adding headersContent-type: text/html
andContent-length
This function will end the http request/response lifecycle.
val text : 'sessionData Req.t -> string -> t -> t Lwt.t
Sends response
t
with bodystring
. Adding headersContent-type: text/plain
andContent-length
This function will end the http request/response lifecycle.
val raw : 'sessionData Req.t -> string -> t -> t Lwt.t
Sends response
t
with bodystring
.This function will add
Content-length
header with the length ofstring
. This function will addConnection: keep-alive
header. This function will end the http request/response lifecycle.
val writeChannel : 'a Req.t -> t -> Lwt_io.output Lwt_io.channel * t Lwt.t
Creates a
Lwt_io.channel(Output)
which can be written to to stream data to the client. And aLwt.t(t)
promise, which will resolve when the output channel is closed. This will setTransfer-Encoding: chunked
header and follow the protocol for chunked responses.
val addHeader : (string * string) -> t -> t
Creates new response from
t
with header(string, string)
added.
val static : string -> string list -> 'sessionData Req.t -> t -> t Lwt.t
Opens file starting at path
string
and followinglist(string)
. SetsContent-type
header based on file extension. If type cannot be inferredtext/plain
is used. SetsContent-length
header with the size of the file in bytes. Responds with404
if file does not exist.This function will end the http request/response lifecycle.
val redirect : string -> 'sessionData Req.t -> t -> t Lwt.t
Sets
Location
header tostring
and responds with302
. Redirecting client tostring
.