Http.ResponseHTTP responses.
The service responses and client responses conventions may help understanding how connectors use and construct these values.
val make :
?headers:Headers.t ->
?log:string ->
?reason:string ->
?version:Version.t ->
Status.t ->
Body.t ->
tmake status body is a response with given status and body and:
headers, the response headers. Defaults to Http.Headers.empty. Note that in general it is better to let bodies define the content type and content length headers. See the service response conventions.log, see log. Defaults to "".reason, the status reason phrase. Defaults to Http.Status.reason_phrase status.version, the HTTP version, see version. Defaults to Version.v11.empty status is make status Body.empty.
val is_empty : t -> boolis_empty response is Body.is_empty (body response).
override_headers ~by response is response with headers Headers.override (headers response) ~by.
with_status status response is response with status status, reason phrase reason (defaults to Http.Status.reason_phrase status, use reason response to keep the previous reason) and log log (defaults to log response).
val pp : Stdlib.Format.formatter -> t -> unitpp formats responses for inspection. Guarantees not consume the body.
val encode_http11 : include_body:bool -> t -> (string, string) Stdlib.resultencode_http11 ~include_body response encodes response to an HTTP/1.1 response. If include_body is true the body is consumed and included in the result. If false the body is left untouched and the encoding stops after the header final double CRLF.
val log : t -> stringlog response is the log of response. The log is a server-side reason not meant to be sent to the client. It can be used to log further details or explanations about the answer that one may not want to disclose to the client.
val reason : t -> stringreason response is the reason phrase of response.
version response is the version of response.
See also request deconstruction combinators.
val content :
?content_type:Media_type.t ->
?headers:Headers.t ->
?log:string ->
?reason:string ->
Status.t ->
string ->
tcontent status s is make status (Body.of_string ?content_type s).
text responds with UTF-8 encoded plain text: content with Media_type.text_plain.
html responds with UTF-8 encoded HTML text: content with Media_type.text_html.
json responds with JSON text: content with Media_type.application_json.
val redirect :
?body:Body.t ->
?headers:Headers.t ->
?log:string ->
?reason:string ->
Status.t ->
string ->
tredirect status loc is a response with status status and Http.Headers.location set to loc on headers. body defaults to Body.empty.
See also Request.redirect_to_path.
Warning. It is your duty to properly percent-encode loc using for example Pct or Path.encode.
val bad_request_400 :
?body:Body.t ->
?headers:Headers.t ->
?log:string ->
?reason:string ->
unit ->
('a, t) Stdlib.resultbad_request_400 () is Error r with r a response with status Status.bad_request_400. body defaults to Body.empty.
val unauthorized_401 :
?body:Body.t ->
?headers:Headers.t ->
?log:string ->
?reason:string ->
unit ->
('a, t) Stdlib.resultunauthorized_401 () is Error r with r a response with status Status.unauthorized_401. body defaults to Body.empty.
val forbidden_403 :
?body:Body.t ->
?headers:Headers.t ->
?log:string ->
?reason:string ->
unit ->
('a, t) Stdlib.resultforbidden_403 () is Error r with r a response with status Status.forbidden_403. body defaults to Body.empty.
val not_found_404 :
?body:Body.t ->
?headers:Headers.t ->
?log:string ->
?reason:string ->
unit ->
('a, t) Stdlib.resultnot_found_404 () is Error r with r a response with status Status.not_found_404. body defaults to Body.empty.
val method_not_allowed_405 :
?body:Body.t ->
?headers:Headers.t ->
?log:string ->
?reason:string ->
allowed:Method.t list ->
unit ->
('a, t) Stdlib.resultmethod_not_allowed_450 ~allowed () is Error r with r a response with status Status.method_not_allowed_405 and Http.Headers.allow set on headers with the allowed methods (which can be empty). body defaults to Body.empty.
val gone_410 :
?body:Body.t ->
?headers:Headers.t ->
?log:string ->
?reason:string ->
unit ->
('a, t) Stdlib.resultgone_410 () is Error r with r a response with status Status.gone_410. body defaults to Body.empty.
val todo :
?body:Body.t ->
?headers:Headers.t ->
?log:string ->
?reason:string ->
unit ->
('a, t) Stdlib.resulttodo is not_implemented_501.
val server_error_500 :
?body:Body.t ->
?headers:Headers.t ->
?log:string ->
?reason:string ->
unit ->
('a, t) Stdlib.resultserver_error_500 () is Error r with r a response with status Status.server_error_500. body defaults to Body.empty.
val not_implemented_501 :
?body:Body.t ->
?headers:Headers.t ->
?log:string ->
?reason:string ->
unit ->
('a, t) Stdlib.resultnot_implemented_501 () is Error r with r a response with status Status.not_implemented_501. body defaults to Body.empty.
service_unavailable_503 () is Error r with r a response with status Status.service_unavailable_503. body defaults to Body.empty.
result r is Result.fold ~ok:Fun.id ~error:Fun.id. It retracts the result type.
map_errors ~only_empty f response maps reponse response with f if r's status is a 4XX or 5XX. If only_empty is true it does so only whenever is_empty response is true.
The idea of map_errors is that service and service building blocks define their errors as responses with empty bodies. This function is then called just before handing over the reponse to the connector to define a page content for response with with_body.