Tiny_httpd_core.ResponseResponses
Responses are what a http server, such as Tiny_httpd, send back to the client to answer a Request.t
Body of a response, either as a simple string, or a stream of bytes, or nothing (for server-sent events notably).
`String str replies with a body set to this string, and a known content-length.`Stream str replies with a body made from this string, using chunked encoding.`Void replies with no body.`Writer w replies with a body created by the writer w, using a chunked encoding. It is available since 0.14.type t = private {code : Response_code.t;headers : Headers.t;Headers of the reply. Some will be set by Tiny_httpd automatically.
body : body;Body of the response. Can be empty.
*)}A response to send back to a client.
val set_code : Response_code.t -> t -> tSet the response code.
val make_raw : ?headers:Headers.t -> code:Response_code.t -> string -> tMake a response from its raw components, with a string body. Use "" to not send a body at all.
val make_raw_stream :
?headers:Headers.t ->
code:Response_code.t ->
IO.Input.t ->
tSame as make_raw but with a stream body. The body will be sent with the chunked transfer-encoding.
val make :
?headers:Headers.t ->
?code:int ->
(body, Response_code.t * string) result ->
tmake r turns a result into a response.
make (Ok body) replies with 200 and the body.make (Error (code,msg)) replies with the given error code and message as body.val make_string :
?headers:Headers.t ->
?code:int ->
(string, Response_code.t * string) result ->
tSame as make but with a string body.
val make_writer :
?headers:Headers.t ->
?code:int ->
(IO.Writer.t, Response_code.t * string) result ->
tSame as make but with a writer body.
val make_stream :
?headers:Headers.t ->
?code:int ->
(IO.Input.t, Response_code.t * string) result ->
tSame as make but with a stream body.
Make the current request fail with the given code and message. Example: fail ~code:404 "oh noes, %s not found" "waldo".
Exception raised by fail_raise with the HTTP code and body
val fail_raise : code:int -> ('a, unit, string, 'b) format4 -> 'aSimilar to fail but raises an exception that exits the current handler. This should not be used outside of a (path) handler. Example: fail_raise ~code:404 "oh noes, %s not found" "waldo"; never_executed()
val pp_with :
?mask_header:(string -> bool) ->
?headers_to_mask:string list ->
?pp_body:(Stdlib.Format.formatter -> body -> unit) ->
unit ->
Stdlib.Format.formatter ->
t ->
unitPretty print the response. The exact format of this printing is not specified.
val pp : Stdlib.Format.formatter -> t -> unitPretty print the response. The exact format is not specified.