(*
OCaml HTTP - do it yourself (fully OCaml) HTTP daemon
- Copyright (C) <2002> Stefano Zacchiroli <zack@cs.unibo.it>
+ Copyright (C) <2002-2004> Stefano Zacchiroli <zack@cs.unibo.it>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*)
-open Http_types;;
-open Printf;;
+open Printf
+open Http_types
-(*
-let wget url =
- prerr_endline (sprintf "DEBUG: wgetting url '%s'" url);
- Http_client.Convenience.http_get url
-in
-*)
-let wget addr port path =
- let rec wget' inchan data =
- try
- wget' inchan (data ^ input_line inchan)
- with End_of_file ->
- data
- in
- prerr_endline (sprintf "DEBUG: wgetting url '%s:%d%s'" addr port path);
- let sockaddr = Unix.ADDR_INET (Unix.inet_addr_of_string addr, port) in
- let suck = Unix.socket Unix.PF_INET Unix.SOCK_STREAM 0 in
- Unix.connect suck sockaddr;
- let outchan = Unix.out_channel_of_descr suck in
- output_string outchan (sprintf "GET %s HTTP/1.0\r\n" path);
- flush outchan;
- let inchan = Unix.in_channel_of_descr suck in
- wget' inchan ""
-in
-let callback (req: request) outchan =
+let callback (req: Http_types.request) outchan =
let i = int_of_string (req#param "x") in
- prerr_endline (string_of_int i);
match i with
- | 0 -> output_string outchan "0"
- | x when x>0 ->
+ | 0 -> output_string outchan "1"
+ | x when x > 0 ->
let data =
- wget "127.0.0.1" 9999 (sprintf "/foo?x=%d" (x-1))
-(* wget (sprintf "http://localhost:9999/foo?x=%d" (x-1)) *)
-(* wget "http://localhost:80/index.html" *)
+ Http_user_agent.get (sprintf "http://127.0.0.1/foo?x=%d" (x - 1))
in
output_string outchan (sprintf "%s %d" data x)
| _ -> assert false
-in
-Http_client.Convenience.http_trials := 1;
-(* Http_daemon.start' ~port:9999 ~mode:`Thread callback *)
-Http_daemon.start' ~port:9999 ~mode:`Fork callback
+
+let spec =
+ { Http_daemon.default_spec with
+ callback = callback;
+ port = 9999;
+ mode = `Thread;
+ }
+
+let _ = Http_daemon.main spec
+