···
1
+
(* Echo server that shows request information *)
5
+
let echo_handler request response =
6
+
let http_req = Responder.request_of_fastcgi request in
7
+
let http_resp = Responder.response_of_fastcgi response in
9
+
http_resp.write_status 200;
10
+
http_resp.write_header "Content-Type" "text/html";
12
+
http_resp.write_body "<h1>FastCGI Echo Server</h1>";
13
+
http_resp.write_body ("<p><strong>Method:</strong> " ^ http_req.method_ ^ "</p>");
14
+
http_resp.write_body ("<p><strong>URI:</strong> " ^ http_req.uri ^ "</p>");
15
+
http_resp.write_body ("<p><strong>Query String:</strong> " ^ http_req.query_string ^ "</p>");
17
+
(match http_req.content_type with
18
+
| Some ct -> http_resp.write_body ("<p><strong>Content-Type:</strong> " ^ ct ^ "</p>")
21
+
(match http_req.content_length with
22
+
| Some cl -> http_resp.write_body ("<p><strong>Content-Length:</strong> " ^ string_of_int cl ^ "</p>")
25
+
http_resp.write_body "<h2>Headers:</h2><ul>";
26
+
List.iter (fun (name, value) ->
27
+
http_resp.write_body ("<li><strong>" ^ name ^ ":</strong> " ^ value ^ "</li>")
29
+
http_resp.write_body "</ul>";
31
+
http_resp.finish ();
33
+
{ app_status = 0; protocol_status = Request_complete }
35
+
let () = Eio_main.run @@ fun env ->
36
+
let net = Eio.Stdenv.net env in
37
+
Eio.Switch.run @@ fun sw ->
38
+
Server.run_default ~sw ~net
39
+
~handler:(Handler.Responder echo_handler)
40
+
~listen_address:(`Tcp ("127.0.0.1", 9001))