Fix main.ml
This commit is contained in:
parent
2714a6d67d
commit
cbc0ad960d
1 changed files with 15 additions and 10 deletions
25
main.ml
25
main.ml
|
@ -1,18 +1,16 @@
|
|||
#require "miou.unix"
|
||||
|
||||
#require "mirage-crypto-rng-miou-unix"
|
||||
|
||||
#require "vif"
|
||||
|
||||
#require "digestif.c"
|
||||
|
||||
#require "base64"
|
||||
#require "miou.unix" ;;
|
||||
#require "mirage-crypto-rng-miou-unix" ;;
|
||||
#require "vif" ;;
|
||||
#require "digestif.c" ;;
|
||||
#require "base64" ;;
|
||||
|
||||
let index server _req () =
|
||||
Vif.Response.with_string server `OK "Hello from an OCaml script!"
|
||||
;;
|
||||
|
||||
let test arg server _req () =
|
||||
Vif.Response.with_string server `OK (Fmt.str "%02x\n%!" arg)
|
||||
;;
|
||||
|
||||
let digest server req () =
|
||||
let ic = Vif.Request.to_stream req in
|
||||
|
@ -24,6 +22,7 @@ let digest server req () =
|
|||
let hash = go Digestif.SHA1.empty in
|
||||
let hash = Digestif.SHA1.to_hex hash in
|
||||
Vif.Response.with_string server `OK hash
|
||||
;;
|
||||
|
||||
let random len server req () =
|
||||
let buf = Bytes.create 0x7ff in
|
||||
|
@ -40,24 +39,30 @@ let random len server req () =
|
|||
end
|
||||
in
|
||||
go len
|
||||
;;
|
||||
|
||||
let routes =
|
||||
let open Vif.U in
|
||||
let open Vif.R in
|
||||
[
|
||||
(rel /?? nil) --> index; (rel / "random" /% Tyre.int /?? nil) --> random
|
||||
(rel /?? nil) --> index
|
||||
; (rel / "random" /% Tyre.int /?? nil) --> random
|
||||
; (rel / "test" /% Tyre.int /?? nil) --> test
|
||||
; (rel / "digest" /?? nil) --> digest
|
||||
]
|
||||
;;
|
||||
|
||||
let default target server req () =
|
||||
Vif.Response.with_string server `Not_found (Fmt.str "%S not found\n%!" target)
|
||||
;;
|
||||
|
||||
let my_device_as_arg, my_device =
|
||||
Vif.D.device ~name:"my-device" ~finally:ignore [] ()
|
||||
;;
|
||||
|
||||
let () =
|
||||
Miou_unix.run @@ fun () ->
|
||||
let sockaddr = Unix.(ADDR_INET (inet_addr_loopback, 8080)) in
|
||||
let cfg = Vif.config sockaddr in
|
||||
Vif.run ~cfg ~default ~devices:Vif.[ D.rng; my_device_as_arg ] routes ()
|
||||
;;
|
||||
|
|
Loading…
Reference in a new issue