-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
36 changed files
with
235 additions
and
230 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,10 @@ | ||
module Mehari_io = Mehari_lwt_unix | ||
open Lwt.Infix | ||
module M = Mehari_lwt_unix | ||
open Lwt.Syntax | ||
|
||
let main () = | ||
X509_lwt.private_of_pems ~cert:"cert.pem" ~priv_key:"key.pem" >>= fun cert -> | ||
Mehari_io.router | ||
[ | ||
Mehari_io.route "/cgi" (fun req -> | ||
Mehari_io.run_cgi "./examples/cgi_script.py" req); | ||
] | ||
|> Mehari_io.run_lwt ~certchains:[ cert ] | ||
let* certchains = Common.Lwt.load_certchains () in | ||
M.router | ||
[ M.route "/cgi" (fun req -> M.run_cgi "./examples/cgi_script.py" req) ] | ||
|> M.run_lwt ~certchains | ||
|
||
let () = Lwt_main.run (main ()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
open Lwt.Infix | ||
|
||
module Lwt = struct | ||
let load_certchains () = | ||
X509_lwt.private_of_pems ~cert:"cert.pem" ~priv_key:"key.pem" | ||
>|= fun cert -> [ cert ] | ||
end | ||
|
||
module Eio = struct | ||
let load_certchains cwd = | ||
Eio.Path. | ||
[ | ||
X509_eio.private_of_pems ~cert:(cwd / "cert.pem") | ||
~priv_key:(cwd / "key.pem"); | ||
] | ||
|
||
let run_server serve = | ||
Eio_main.run @@ fun env -> | ||
Mirage_crypto_rng_eio.run (module Mirage_crypto_rng.Fortuna) env | ||
@@ fun () -> serve ~net:env#net ~cwd:env#cwd | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,13 @@ | ||
module Mehari_io = Mehari_lwt_unix | ||
open Lwt.Infix | ||
module M = Mehari_lwt_unix | ||
open Lwt.Syntax | ||
|
||
let main () = | ||
X509_lwt.private_of_pems ~cert:"cert.pem" ~priv_key:"key.pem" >>= fun cert -> | ||
Mehari_io.router | ||
let* certchains = Common.Lwt.load_certchains () in | ||
M.router | ||
[ | ||
Mehari_io.route ~regex:true "/echo/(.*)" (fun req -> | ||
Mehari.param req 1 |> Mehari_io.respond_text); | ||
M.route ~regex:true "/echo/(.*)" (fun req -> | ||
Mehari.param req 1 |> M.respond_text); | ||
] | ||
|> Mehari_io.logger | ||
|> Mehari_io.run_lwt ~certchains:[ cert ] | ||
|> M.logger |> M.run_lwt ~certchains | ||
|
||
let () = Lwt_main.run (main ()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
open Lwt.Infix | ||
open Lwt.Syntax | ||
|
||
let main () = | ||
X509_lwt.private_of_pems ~cert:"cert.pem" ~priv_key:"key.pem" | ||
>>= fun certchain -> | ||
let* certchains = Common.Lwt.load_certchains () in | ||
(fun _ -> Mehari_lwt_unix.respond_text "Hello") | ||
|> Mehari_lwt_unix.run_lwt ~certchains:[ certchain ] | ||
|> Mehari_lwt_unix.run_lwt ~certchains | ||
|
||
let () = Lwt_main.run (main ()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,22 @@ | ||
module Mehari_io = Mehari_lwt_unix | ||
open Lwt.Infix | ||
module M = Mehari_lwt_unix | ||
open Lwt.Syntax | ||
|
||
let n = ref 0 | ||
|
||
let ipv4 = | ||
Ipaddr.V4.of_string "192.168.1.37" | ||
|> Result.get_ok |> Ipaddr.V4.Prefix.of_addr | ||
|
||
let () = | ||
Mehari_io.set_log_lvl Info; | ||
M.set_log_lvl Info; | ||
Logs.set_level (Some Info); | ||
Logs.set_reporter (Logs_fmt.reporter ()) | ||
|
||
let main () = | ||
X509_lwt.private_of_pems ~cert:"cert.pem" ~priv_key:"key.pem" >>= fun cert -> | ||
Mehari_io.router | ||
let* certchains = Common.Lwt.load_certchains () in | ||
M.router | ||
[ | ||
Mehari_io.route "/" (fun _ -> | ||
M.route "/" (fun _ -> | ||
incr n; | ||
Mehari_io.info (fun log -> log "Request n°: %i" !n); | ||
Mehari_io.respond_text "This request is logged"); | ||
M.info (fun log -> log "Request n°: %i" !n); | ||
M.respond_text "This request is logged"); | ||
] | ||
|> Mehari_io.logger | ||
|> Mehari_io.run_lwt ~v4:ipv4 ~certchains:[ cert ] | ||
|> M.logger |> M.run_lwt ~certchains | ||
|
||
let () = Lwt_main.run (main ()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
module Mehari_io = Mehari_lwt_unix | ||
open Lwt.Infix | ||
module M = Mehari_lwt_unix | ||
open Lwt.Syntax | ||
|
||
let low_limit = Mehari_io.make_rate_limit 5 `Minute | ||
let high_limit = Mehari_io.make_rate_limit ~period:10 2 `Second | ||
let low_limit = M.make_rate_limit 5 `Minute | ||
let high_limit = M.make_rate_limit ~period:10 2 `Second | ||
|
||
let main () = | ||
X509_lwt.private_of_pems ~cert:"cert.pem" ~priv_key:"key.pem" >>= fun cert -> | ||
Mehari_io.router | ||
let* certchains = Common.Lwt.load_certchains () in | ||
M.router | ||
[ | ||
Mehari_io.route "/low" ~rate_limit:low_limit (fun _ -> | ||
Mehari_io.respond_text "5 requests per minute authorized"); | ||
Mehari_io.route "/high" ~rate_limit:high_limit (fun _ -> | ||
Mehari_io.respond_text "2 requests per 10 seconds authorized"); | ||
M.route "/low" ~rate_limit:low_limit (fun _ -> | ||
M.respond_text "5 requests per minute authorized"); | ||
M.route "/high" ~rate_limit:high_limit (fun _ -> | ||
M.respond_text "2 requests per 10 seconds authorized"); | ||
] | ||
|> Mehari_io.run_lwt ~certchains:[ cert ] | ||
|> M.run_lwt ~certchains | ||
|
||
let () = Lwt_main.run (main ()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# This file is generated by dune, edit dune-project instead | ||
opam-version: "2.0" | ||
version: "0.3" | ||
version: "0.4" | ||
synopsis: "Mehari IO implementation using Eio" | ||
maintainer: ["[email protected]" "[email protected]"] | ||
authors: ["The mehari programmers"] | ||
|
@@ -11,7 +11,7 @@ depends: [ | |
"dune" {>= "3.0"} | ||
"ocaml" {>= "5.0.0"} | ||
"mehari" {= version} | ||
"eio" {>= "0.8"} | ||
"eio" {>= "1.0"} | ||
"logs" {>= "0.7.0"} | ||
"tls" {>= "0.15.4"} | ||
"tls-eio" {>= "0.15.5"} | ||
|
Oops, something went wrong.