Module Naboris.Res
Module for creating and sending responses.
val default : unit -> tCreates a default response record with empty headers and a 200 status.
val json : 'sessionData Req.t -> string -> t -> t Lwt.tSends response
twith bodystring. Adding headersContent-type: application/jsonandContent-lengthThis function will end the http request/response lifecycle.
val html : 'sessionData Req.t -> string -> t -> t Lwt.tSends response
twith bodystring. Adding headersContent-type: text/htmlandContent-lengthThis function will end the http request/response lifecycle.
val text : 'sessionData Req.t -> string -> t -> t Lwt.tSends response
twith bodystring. Adding headersContent-type: text/plainandContent-lengthThis function will end the http request/response lifecycle.
val raw : 'sessionData Req.t -> string -> t -> t Lwt.tSends response
twith bodystring.This function will add
Content-lengthheader with the length ofstring. This function will addConnection: keep-aliveheader. This function will end the http request/response lifecycle.
val writeChannel : 'a Req.t -> t -> Lwt_io.output Lwt_io.channel * t Lwt.tCreates 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: chunkedheader and follow the protocol for chunked responses.
val addHeader : (string * string) -> t -> tCreates new response from
twith header(string, string)added.
val static : string -> string list -> 'sessionData Req.t -> t -> t Lwt.tOpens file starting at path
stringand followinglist(string). SetsContent-typeheader based on file extension. If type cannot be inferredtext/plainis used. SetsContent-lengthheader with the size of the file in bytes. Responds with404if file does not exist.This function will end the http request/response lifecycle.
val redirect : string -> 'sessionData Req.t -> t -> t Lwt.tSets
Locationheader tostringand responds with302. Redirecting client tostring.