open Netcgi let text = Netencoding.Html.encode_from_latin1 (* This function encodes "<", ">", "&", double quotes, and Latin 1 characters as character entities. E.g. text "<" = "<", and text "ä" = "ä" *) (* Normally you would use a template system instead of this *) let html_page (cgi:cgi) title html = let out = cgi#out_channel#output_string in out "\n"; out ("\n" ^ text title ^" \n"); out html; out "\n" let main (cgi:cgi) = cgi#set_header ~cache:`No_cache ~content_type:"text/html; charset=\"iso-8859-1\"" (); let foo = cgi#argument_value "foo" let html = match foo with | "1" -> "Yes" | "0" -> "No" | _ -> "Undefined" in html_page cgi foo html (* You can buffer or not the output. If buffered you can rollback (useful in case of error). You can replace Netcgi_cgi.run by another connector entry point (FCGI, SCGI, AJP, Apache mod). *) let () = let buffered _ ch = new Netchannels.buffered_trans_channel ch in Netcgi_cgi.run ~output_type:(`Transactional buffered) main