Http.ResponseHTTP responses.
These values are:
val make :
?headers:Http.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.val empty :
?headers:Http.Headers.t ->
?log:string ->
?reason:string ->
Status.t ->
tempty status is make status Body.empty.
val with_headers : Http.Headers.t -> t -> twith_headers hs response is response with headers hs.
val override_headers : by:Http.Headers.t -> t -> toverride_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 headers : t -> Http.Headers.theaders response are the headers of response.
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.
val is_empty : t -> boolis_empty response is Body.is_empty (body response).
See also request deconstruction combinators.
val content :
?content_type:Media_type.t ->
?headers:Http.Headers.t ->
?log:string ->
?reason:string ->
Status.t ->
string ->
tcontent status s is make status (Body.of_string ?content_type s).
val text :
?headers:Http.Headers.t ->
?log:string ->
?reason:string ->
Status.t ->
string ->
ttext responds with UTF-8 encoded plain text. This is content with Media_type.text_plain.
val html :
?headers:Http.Headers.t ->
?log:string ->
?reason:string ->
Status.t ->
string ->
thtml responds with UTF-8 encoded HTML text. This is content with Media_type.text_html.
val json :
?headers:Http.Headers.t ->
?log:string ->
?reason:string ->
Status.t ->
string ->
tjson responds with JSON text. This is content with Media_type.application_json.
val redirect :
?body:Body.t ->
?headers:Http.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 Webs.Url.Percent or Path.encode.
val bad_request_400 :
?body:Body.t ->
?headers:Http.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:Http.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:Http.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:Http.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:Http.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:Http.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:Http.Headers.t ->
?log:string ->
?reason:string ->
unit ->
('a, t) Stdlib.resulttodo is not_implemented_501.
val server_error_500 :
?body:Body.t ->
?headers:Http.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:Http.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.
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.