package dream

  1. Overview
  2. Docs

Source file tag.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#1 "src/server/tag.eml.ml"
(* This file is part of Dream, released under the MIT license. See LICENSE.md
   for details, or visit https://github.com/aantron/dream.

   Copyright 2021 Anton Bachin *)



module Dream =
struct
  include Dream_pure
  include Dream_pure.Formats
end
(* This slightly awkward simulation of the overall Dream module using a
   composition of internal modules is necessary to get all the helpers at the
   right positions expected by the EML templater. *)
module Method = Dream_pure.Method


let csrf_tag ~now request =
  let token = Csrf.csrf_token ~now request in
let ___eml_buffer = Buffer.create 4096 in
(Buffer.add_string ___eml_buffer "<input name=\"");
(Printf.bprintf ___eml_buffer "%s" (
#21 "src/server/tag.eml.ml"
                    Csrf.field_name 
));
(Buffer.add_string ___eml_buffer "\" type=\"hidden\" value=\"");
(Printf.bprintf ___eml_buffer "%s" (
#21 "src/server/tag.eml.ml"
                                                                  token 
));
(Buffer.add_string ___eml_buffer "\">\n\n");
(Buffer.contents ___eml_buffer)
#23 "src/server/tag.eml.ml"
(* TODO Include the path prefix. *)
let form_tag
    ~now ?method_ ?target ?enctype ?csrf_token ~action request =

  let method_ =
    match method_ with
    | None -> Method.method_to_string `POST
    | Some method_ -> Method.method_to_string method_
  in
  let target =
    match target with
    | Some target -> " target=\"" ^ Dream.html_escape target ^ "\""
    | None -> ""
  in
  let enctype =
    match enctype with
    | Some `Multipart_form_data -> " enctype=\"multipart/form-data\""
    | None -> ""
  in
  let csrf_token =
    match csrf_token with
    | None -> true
    | Some csrf_token -> csrf_token
  in
let ___eml_buffer = Buffer.create 4096 in
(Buffer.add_string ___eml_buffer "<form\n  method=\"");
(Printf.bprintf ___eml_buffer "%s" (
#48 "src/server/tag.eml.ml"
                 method_ 
));
(Buffer.add_string ___eml_buffer "\"\n  action=\"");
(Printf.bprintf ___eml_buffer "%s" (Dream.html_escape (
#49 "src/server/tag.eml.ml"
                action 
)));
(Buffer.add_string ___eml_buffer "\"");
(Printf.bprintf ___eml_buffer "%s" (
#49 "src/server/tag.eml.ml"
                               target 
));
(Printf.bprintf ___eml_buffer "%s" (
#49 "src/server/tag.eml.ml"
                                             enctype 
));
(Buffer.add_string ___eml_buffer ">\n");
#50 "src/server/tag.eml.ml"
  if csrf_token then begin

(Buffer.add_string ___eml_buffer "    ");
(Printf.bprintf ___eml_buffer "%s" (
#51 "src/server/tag.eml.ml"
         csrf_tag ~now request 
));
(Buffer.add_string ___eml_buffer "\n");
#52 "src/server/tag.eml.ml"
  end;

(Buffer.contents ___eml_buffer)
OCaml

Innovation. Community. Security.