forked from ahrefs/devkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_httpev.ml
More file actions
27 lines (23 loc) · 751 Bytes
/
test_httpev.ml
File metadata and controls
27 lines (23 loc) · 751 Bytes
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
(** Bare-bones httpev server example *)
open Printf
open Devkit
let log = Httpev.Hidden.log
let http_handle _st req k_http =
let module Arg = Httpev.Args(struct let req = req end) in
match req.Httpev.path with
| "/hello" ->
let name = Option.default "world" (Arg.get "name") in
k_http @@ Httpev.serve_text req (sprintf "Hello, %s!" name)
| _ ->
log #warn "not found : %s" (Httpev.show_request req);
k_http @@ Httpev.not_found
let run http_port =
let main () =
let http_config = { Httpev.default with
Httpev.events = Async.Ev.init ();
connection = ADDR_INET (Unix.inet_addr_any, http_port);
max_request_size = 128 * 1024;
} in
Httpev.server http_config http_handle;
in
Action.log main ()