11 let document heading extra x
=
12 html ~a
:[a_xmlns `W3_org_1999_xhtml
; a_xml_lang
"en"]
13 (head
(title
(t heading
)) extra
)
16 let doc heading x
= document heading
[] x
19 doc "Main page" [p
[t"hello"]]
23 let encode = Netencoding.Html.encode ~in_enc
:`Enc_utf8 ~out_enc
:`Enc_utf8
()
26 let env = cgi#environment
in
27 (* let cgi_arg name = try Some (cgi#argument name)#value with _ -> None in *)
28 let outs = cgi#out_channel#output_string
in
29 let out fmt
= ksprintf
outs fmt
in
30 let serve_text () = cgi#set_header ~cache
:`No_cache ~content_type
:"text/plain" () in
32 cgi#set_header ~cache
:`No_cache ~content_type
:"text/html" ();
33 XHTML.M.output ~
encode ~encoding
:"utf-8" outs html
37 out "\ncgi_properties\n";
38 List.iter
(fun (k
,v
) -> out "%s = %s\n" k v
) env#cgi_properties
;
39 out "\ninput_header_fields\n";
40 List.iter
(fun (k
,v
) -> out "%s = %s\n" k v
) env#input_header_fields
;
41 out "\ncgi_arguments\n";
42 List.iter
(fun x
-> out "%s = %s\n" x#name x#
value) cgi#arguments
45 let path = match env#cgi_path_info
with "" -> env#cgi_property ~default
:"" "REQUEST_URI" | s
-> s
in
48 | "/" -> serve_html (Page.main ());
49 | "/dump" -> serve_text (); dump_cgi ()
51 cgi#set_header ~cache
:`No_cache ~content_type
:"text/plain" ~status
:`Not_found
();
57 cgi#out_channel#commit_work
();
59 _
-> cgi#out_channel#rollback_work
()