File: hello.ml

package info (click to toggle)
ocamlnet 4.1.9-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 54,024 kB
  • sloc: ml: 151,939; ansic: 11,071; sh: 2,003; makefile: 1,310
file content (33 lines) | stat: -rw-r--r-- 961 bytes parent folder | download | duplicates (10)
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
(* Simple script to demonstrate the use of templates. *)

open Netcgi

(* Normally, you should put the template into a file and load it with
   [Netcgi_modtpl.template filename].  We have inlined it here for
   simplicity.  *)
let template = Netcgi_modtpl.template_from_string "\
<html>
  <head><title>::title_html::</title></head>
  <body bgcolor=\"#ffffff\">
    <h1>::title_html::</h1>
    <p>
      <b>If you see this message, then everything looks like it's installed
      and working fine!</b>
    </p>
  </body>
</html>"

let main (cgi:cgi) =
  template#set "title" "Hello, world.";
  cgi#set_header
    ~cache:`No_cache
    ~content_type:"text/html; charset=\"iso-8859-1\""
    ();
  template#output cgi


let () =
  let buffered _ ch = new Netchannels.buffered_trans_channel ch in
  (* To use a different connector, just change the next line -- the rest of
     the code stays the same. *)
  Netcgi_cgi.run ~output_type:(`Transactional buffered) main