You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

29 lines
1.1 KiB

let handle_invalid_form = function
| `Ok _ -> Dream.respond ~status:`Bad_Request "invalid form"
| `Many_tokens _ | `Missing_token _ | `Invalid_token _ | `Wrong_session _
| `Expired _ | `Wrong_content_type ->
Dream.empty `Bad_Request
let asset_loader _root path _request =
match Content.read ("assets/" ^ path) with
| None -> Dream.empty `Not_Found
| Some asset ->
(* TODO cache-control: ~headers:[ ("Cache-Control", "max-age=151200") ] *)
Dream.respond asset
let error_template _error _debug_info response =
let open Lwt.Syntax in
let status = Dream.status response in
let code = Dream.status_to_int status in
(*TODO improve: can't use template.elm.html because it needs "request" *)
let* body = Dream.body response in
let reason =
if String.equal "" body then Dream.status_to_string status else body
in
Dream.set_body response (Format.sprintf "%d: %s" code reason);
Lwt.return response
let csrf_tag request =
let open Tyxml.Html in
let token = Dream.csrf_token request in
input ~a:[ a_name "dream.csrf"; a_input_type `Hidden; a_value token ] ()