-
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.
Merge pull request #63 from Psi-Prod/dev
Mehari 0.2
- Loading branch information
Showing
50 changed files
with
457 additions
and
379 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ _opam/ | |
.DS_Store | ||
|
||
# Certificates | ||
*.key | ||
*.pem | ||
|
||
# Sublime Text | ||
|
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,9 +1,13 @@ | ||
module Mehari_io = Mehari_lwt_unix | ||
open Lwt.Infix | ||
|
||
let () = | ||
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 | ||
|> Mehari_io.run_lwt ~certchains:[ cert ] | ||
|
||
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,23 +1,26 @@ | ||
open Mehari | ||
module Mehari_io = Mehari_lwt_unix | ||
open Lwt.Infix | ||
|
||
let counter = ref 0 | ||
|
||
let incr_count handler req = | ||
incr counter; | ||
handler req | ||
|
||
let () = | ||
let main () = | ||
X509_lwt.private_of_pems ~cert:"cert.pem" ~priv_key:"key.pem" >>= fun cert -> | ||
Mehari_io.router | ||
[ | ||
Mehari_io.route "/" (fun _ -> | ||
let open Mehari.Gemtext in | ||
Mehari_io.respond_gemtext | ||
Gemtext. | ||
[ | ||
link "/incr" ~name:"Increment counter"; | ||
text (Printf.sprintf "Counter = %i" !counter); | ||
]); | ||
[ | ||
link "/incr" ~name:"Increment counter"; | ||
text (Printf.sprintf "Counter = %i" !counter); | ||
]); | ||
Mehari_io.route "/incr" ~mw:incr_count (fun _ -> | ||
Mehari_io.respond Mehari.redirect_temp "/"); | ||
] | ||
|> Mehari_io.run | ||
|> Mehari_io.run_lwt ~certchains:[ cert ] | ||
|
||
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 |
---|---|---|
|
@@ -17,7 +17,6 @@ | |
eio_main | ||
mehari | ||
mehari-eio | ||
mehari-eio-unix | ||
mehari-lwt-unix | ||
mirage-crypto-rng-eio | ||
logs | ||
|
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,14 @@ | ||
module Mehari_io = Mehari_lwt_unix | ||
open Lwt.Infix | ||
|
||
let () = | ||
let main () = | ||
X509_lwt.private_of_pems ~cert:"cert.pem" ~priv_key:"key.pem" >>= fun cert -> | ||
Mehari_io.router | ||
[ | ||
Mehari_io.route ~typ:`Regex "/echo/(.*)" (fun req -> | ||
Mehari_io.route ~regex:true "/echo/(.*)" (fun req -> | ||
Mehari.param req 1 |> Mehari_io.respond_text); | ||
] | ||
|> Mehari_io.logger |> Mehari_io.run | ||
|> Mehari_io.logger | ||
|> Mehari_io.run_lwt ~certchains:[ cert ] | ||
|
||
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 +1,9 @@ | ||
let () = (fun _ -> Mehari_lwt_unix.respond_text "Hello") |> Mehari_lwt_unix.run | ||
open Lwt.Infix | ||
|
||
let main () = | ||
X509_lwt.private_of_pems ~cert:"cert.pem" ~priv_key:"key.pem" | ||
>>= fun certchain -> | ||
(fun _ -> Mehari_lwt_unix.respond_text "Hello") | ||
|> Mehari_lwt_unix.run_lwt ~certchains:[ certchain ] | ||
|
||
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,17 +1,27 @@ | ||
module Mehari_io = Mehari_lwt_unix | ||
open Lwt.Infix | ||
|
||
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; | ||
Logs.set_level (Some Info); | ||
Logs.set_reporter (Logs_fmt.reporter ()) | ||
|
||
let () = | ||
let main () = | ||
X509_lwt.private_of_pems ~cert:"cert.pem" ~priv_key:"key.pem" >>= fun cert -> | ||
Mehari_io.router | ||
[ | ||
Mehari_io.route "/" (fun _ -> | ||
incr n; | ||
Mehari_io.info (fun log -> log "Request n°: %i" !n); | ||
Mehari_io.respond_text "This request is logged"); | ||
] | ||
|> Mehari_io.logger |> Mehari_io.run | ||
|> Mehari_io.logger | ||
|> Mehari_io.run_lwt ~v4:ipv4 ~certchains:[ cert ] | ||
|
||
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,14 +1,18 @@ | ||
module Mehari_io = Mehari_lwt_unix | ||
open Lwt.Infix | ||
|
||
let low_limit = Mehari_io.make_rate_limit 5 `Minute | ||
let high_limit = Mehari_io.make_rate_limit ~period:10 2 `Second | ||
|
||
let () = | ||
let main () = | ||
X509_lwt.private_of_pems ~cert:"cert.pem" ~priv_key:"key.pem" >>= fun cert -> | ||
Mehari_io.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"); | ||
] | ||
|> Mehari_io.run | ||
|> Mehari_io.run_lwt ~certchains:[ cert ] | ||
|
||
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,29 @@ | ||
open Mirage | ||
|
||
let port = | ||
let doc = | ||
Key.Arg.info | ||
~doc:"The TCP port on which to listen for incoming connections." | ||
[ "port" ] | ||
in | ||
Key.(create "port" Arg.(opt (some int) None doc)) | ||
|
||
let static_key = Key.(value @@ kv_ro ~group:"static" ()) | ||
let static = generic_kv_ro ~key:static_key "gemtext" | ||
let certs_key = Key.(value @@ kv_ro ~group:"certs" ()) | ||
let certs = generic_kv_ro ~key:certs_key "tls" | ||
|
||
let main = | ||
foreign | ||
~keys:Key.[ v port ] | ||
~packages:[ package "mehari"; package "mehari-mirage" ] | ||
"Unikernel.GeminiServer" | ||
(random @-> kv_ro @-> kv_ro @-> pclock @-> stackv4v6 @-> time @-> job) | ||
|
||
let () = | ||
register "gemini-srv" | ||
[ | ||
main $ default_random $ static $ certs $ default_posix_clock | ||
$ generic_stackv4v6 default_network | ||
$ default_time; | ||
] |
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 @@ | ||
# My gemlog |
Oops, something went wrong.