forked from mirage/mirage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
http_hello.ml
52 lines (38 loc) · 954 Bytes
/
http_hello.ml
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
(* Simple hello world webserver *)
open Printf
open Lwt
let auth = `None
let conn_closed id =
()
let port = 80
let callback id req =
Http.Server.respond ~body:"hello mirage world"
~headers:["x-foo","bar"] ()
let exn_handler exn =
printf "exn: %s\n%!" (Printexc.to_string exn);
return ()
let spec = {
Http.Server.address="foo";
auth = `None;
callback;
conn_closed;
port;
exn_handler;
timeout= None
}
let ip = Net.Nettypes.(
(ipv4_addr_of_tuple (10l,0l,0l,2l),
ipv4_addr_of_tuple (255l,255l,255l,0l),
[ ipv4_addr_of_tuple (10l,0l,0l,2l) ]
))
let print_data =
while_lwt true do
Printf.printf ">>>>>>>>>>>>>>>> live_words = %d\n%!" Gc.((stat()).live_words);
OS.Time.sleep 3.0
done
let main () =
Log.info "Echo" "starting server";
Net.Manager.create (fun mgr interface id ->
lwt () = Net.Manager.configure interface (`IPv4 ip) in
Http.Server.listen mgr (`TCPv4 ((None, port), spec))
)