2 OCaml HTTP - do it yourself (fully OCaml) HTTP daemon
4 Copyright (C) <2002-2007> Stefano Zacchiroli <zack@cs.unibo.it>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 let callback req outchan =
26 (sprintf "request path = %s\n" req#path) ^
27 (sprintf "request GET params = %s\n"
29 (List.map (fun (h,v) -> String.concat "=" [h;v]) req#params_GET))) ^
30 (sprintf "request POST params = %s\n"
32 (List.map (fun (h,v) -> String.concat "=" [h;v]) req#params_POST))) ^
33 (sprintf "request ALL params = %s\n"
35 (List.map (fun (h,v) -> String.concat "=" [h;v]) req#params))) ^
36 (sprintf "cookies = %s\n"
37 (match req#cookies with
40 ^ (if req#hasHeader ~name:"cookie"
41 then "('Cookie:' header was '" ^ req#header ~name:"cookie" ^ "')"
42 else "(No 'Cookie:' header received)")
45 (List.map (fun (n,v) -> String.concat "=" [n;v]) cookies)))) ^
46 (sprintf "request BODY = '%s'\n\n" req#body)
48 Http_daemon.respond ~code:(`Code 200) ~body: str outchan
51 { Http_daemon.default_spec with
56 let _ = Http_daemon.main spec