Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port to Eio and Cohttp #327

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PACKAGES := dream-pure,dream-httpaf,dream
PACKAGES := dream-pure,dream

.PHONY : build
build :
Expand All @@ -10,7 +10,7 @@ watch :

.PHONY : deps
deps :
opam install --deps-only --with-test ./dream-pure.opam ./dream-httpaf.opam ./dream.opam
opam install --deps-only --with-test ./dream-pure.opam ./dream.opam

TEST ?= test
ROOT := $(shell [ -f ../dune-workspace ] && echo .. || echo .)
Expand Down
24 changes: 12 additions & 12 deletions dream-httpaf.opam
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ maintainer: "Anton Bachin <[email protected]>"
depends: [
"dream-pure"
"dune" {>= "2.7.0"} # --instrument-with.
"lwt"
"lwt_ppx" {>= "1.2.2"}
"lwt_ssl"
# "lwt"
# "lwt_ppx" {>= "1.2.2"}
# "lwt_ssl"
"ocaml" {>= "4.08.0"}
"ssl" {>= "0.5.8"} # Ssl.get_negotiated_alpn_protocol.
# "ssl" {>= "0.5.8"} # Ssl.get_negotiated_alpn_protocol.

# Currently vendored.
# "gluten"
Expand All @@ -32,14 +32,14 @@ depends: [
# "websocketaf"

# Dependencies of vendored packages.
"angstrom" {>= "0.14.0"}
"base64" {>= "3.0.0"}
"bigstringaf" {>= "0.5.0"} # h2.
"digestif" {>= "0.7.2"} # websocket/af, sha1, default implementation.
"faraday" {>= "0.6.1"}
"faraday-lwt-unix"
"lwt_ssl" {>= "1.2.0"} # Gluten.
"psq" # h2.
# "angstrom" {>= "0.14.0"}
# "base64" {>= "3.0.0"}
# "bigstringaf" {>= "0.5.0"} # h2.
# "digestif" {>= "0.7.2"} # websocket/af, sha1, default implementation.
# "faraday" {>= "0.6.1"}
# "faraday-lwt-unix"
# "lwt_ssl" {>= "1.2.0"} # Gluten.
# "psq" # h2.
]

build: [
Expand Down
3 changes: 1 addition & 2 deletions dream-pure.opam
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ depends: [
"base64" {>= "3.1.0"} # Base64.encode_string.
"bigstringaf" {>= "0.5.0"} # Bigstringaf.to_string.
"dune" {>= "2.7.0"} # --instrument-with.
"eio"
"hmap"
"lwt"
"lwt_ppx" {>= "1.2.2"}
"ocaml" {>= "4.08.0"}
"ptime" {>= "0.8.1"} # Ptime.weekday.
"uri" {>= "4.2.0"}
Expand Down
14 changes: 6 additions & 8 deletions dream.opam
Original file line number Diff line number Diff line change
Expand Up @@ -51,28 +51,25 @@ depends: [
"bigarray-compat"
"camlp-streams"
"caqti" {>= "2.0.0"}
"caqti-lwt" {>= "2.0.0"}
"cohttp-eio"
("conf-libev" {os != "win32"} | "ocaml" {os = "win32"})
"cstruct" {>= "6.0.0"}
"dream-httpaf" {>= "1.0.0~alpha3"}
"digestif" {>= "0.7"}
"dream-pure" {>= "1.0.0~alpha2"}
"dune" {>= "2.7.0"} # --instrument-with.
"eio"
"fmt" {>= "0.8.7"} # `Italic.
"graphql_parser"
"graphql-lwt"
"http"
"lambdasoup" {>= "0.6.1"}
"lwt"
"lwt_ppx" {>= "1.2.2"}
"lwt_ssl"
"logs" {>= "0.5.0"}
"magic-mime"
"markup" {>= "1.0.2"}
"mirage-clock" {>= "3.0.0"} # now_d_ps : unit -> int * int64.
"mirage-crypto" {>= "0.8.1"} # AES-256-GCM.
"mirage-crypto-rng"
"mirage-crypto-rng-lwt"
"mirage-crypto-rng-eio"
"multipart_form" {>= "0.4.0"}
"multipart_form-lwt"
"ocaml" {>= "4.08.0"}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can just remove the OCaml version since Eio will force >5

"ptime" {>= "0.8.1"} # Ptime.v.
"ssl" {>= "0.5.8"} # Ssl.get_negotiated_alpn_protocol.
Expand All @@ -85,6 +82,7 @@ depends: [
"caqti-driver-postgresql" {with-test}
"caqti-driver-sqlite3" {with-test}
"crunch" {with-test}
"eio_main" {with-test}
"js_of_ocaml" {with-test}
"js_of_ocaml-ppx" {with-test}
"ppx_expect" {with-test & >= "v0.15.0"} # Formatting changes.
Expand Down
2 changes: 1 addition & 1 deletion example/1-hello/dune
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
(executable
(name hello)
(libraries dream))
(libraries dream eio_main))
6 changes: 4 additions & 2 deletions example/1-hello/hello.ml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
let () =
Dream.run (fun _ ->
Dream.html "Good morning, world!")
Eio_main.run begin fun env ->
Dream.run env (fun _ ->
Dream.html "Good morning, world!")
end
2 changes: 1 addition & 1 deletion example/2-middleware/dune
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
(executable
(name middleware)
(libraries dream))
(libraries dream eio_main))
8 changes: 5 additions & 3 deletions example/2-middleware/middleware.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
let () =
Dream.run
@@ Dream.logger
@@ fun _ -> Dream.html "Good morning, world!"
Eio_main.run begin fun env ->
Dream.run env
@@ Dream.logger
@@ fun _ -> Dream.html "Good morning, world!"
end
2 changes: 1 addition & 1 deletion example/3-router/dune
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
(executable
(name router)
(libraries dream))
(libraries dream eio_main))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't eio_main get pulled in transitively by dream? In the same way that lwt.unix was before.

4 changes: 2 additions & 2 deletions example/3-router/router.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
let () =
Dream.run
let () = Eio_main.run @@ fun env ->
Dream.run env
@@ Dream.logger
@@ Dream.router [

Expand Down
4 changes: 2 additions & 2 deletions example/4-counter/counter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ let count_requests inner_handler request =
count := !count + 1;
inner_handler request

let () =
Dream.run
let () = Eio_main.run @@ fun env ->
Dream.run env
@@ Dream.logger
@@ count_requests
@@ Dream.router [
Expand Down
2 changes: 1 addition & 1 deletion example/4-counter/dune
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
(executable
(name counter)
(libraries dream))
(libraries dream eio_main))
3 changes: 1 addition & 2 deletions example/6-echo/dune
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
(executable
(name echo)
(libraries dream)
(preprocess (pps lwt_ppx)))
(libraries dream eio_main))
6 changes: 3 additions & 3 deletions example/6-echo/echo.ml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
let () =
Dream.run
let () = Eio_main.run @@ fun env ->
Dream.run env
@@ Dream.logger
@@ Dream.router [

Dream.post "/echo" (fun request ->
let%lwt body = Dream.body request in
let body = Dream.body request in
Dream.respond
~headers:["Content-Type", "application/octet-stream"]
body);
Expand Down
2 changes: 1 addition & 1 deletion example/7-template/dune
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(executable
(name template)
(libraries dream))
(libraries dream eio_main))

(rule
(targets template.ml)
Expand Down
4 changes: 2 additions & 2 deletions example/7-template/template.eml.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ let render param =
</body>
</html>

let () =
Dream.run
let () = Eio_main.run @@ fun env ->
Dream.run env
@@ Dream.logger
@@ Dream.router [

Expand Down
4 changes: 2 additions & 2 deletions example/8-debug/debug.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
let () =
Dream.run ~error_handler:Dream.debug_error_handler
let () = Eio_main.run @@ fun env ->
Dream.run ~error_handler:Dream.debug_error_handler env
@@ Dream.logger
@@ Dream.router [

Expand Down
2 changes: 1 addition & 1 deletion example/8-debug/dune
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
(executable
(name debug)
(libraries dream))
(libraries dream eio_main))
2 changes: 1 addition & 1 deletion example/9-error/dune
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(executable
(name error)
(libraries dream))
(libraries dream eio_main))

(rule
(targets error.ml)
Expand Down
6 changes: 3 additions & 3 deletions example/9-error/error.eml.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ let my_error_template _error debug_info suggested_response =
</body>
</html>
end;
Lwt.return suggested_response
suggested_response

let () =
Dream.run ~error_handler:(Dream.error_template my_error_template)
let () = Eio_main.run @@ fun env ->
Dream.run ~error_handler:(Dream.error_template my_error_template) env
@@ Dream.logger
@@ fun _ -> Dream.empty `Not_Found
2 changes: 1 addition & 1 deletion example/a-log/dune
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
(executable
(name log)
(libraries dream))
(libraries dream eio_main))
4 changes: 2 additions & 2 deletions example/a-log/log.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
let () =
Dream.run
let () = Eio_main.run @@ fun env ->
Dream.run env
@@ Dream.logger
@@ Dream.router [

Expand Down
3 changes: 1 addition & 2 deletions example/b-session/dune
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
(executable
(name session)
(libraries dream)
(preprocess (pps lwt_ppx)))
(libraries dream eio_main))
12 changes: 6 additions & 6 deletions example/b-session/session.ml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
let () =
Dream.run
let () = Eio_main.run @@ fun env ->
Dream.run env
@@ Dream.logger
@@ Dream.memory_sessions
@@ fun request ->

match Dream.session_field request "user" with
| None ->
let%lwt () = Dream.invalidate_session request in
let%lwt () = Dream.set_session_field request "user" "alice" in
Dream.invalidate_session request;
Dream.set_session_field request "user" "alice";
Dream.html "You weren't logged in; but now you are!"

| Some username ->
Printf.ksprintf
Dream.html "Welcome back, %s!" (Dream.html_escape username)
Dream.html
(Printf.sprintf "Welcome back, %s!" (Dream.html_escape username))
6 changes: 3 additions & 3 deletions example/c-cookie/cookie.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
let () =
Dream.run
let () = Eio_main.run @@ fun env ->
Dream.run env
@@ Dream.set_secret "foo"
@@ Dream.logger
@@ fun request ->
Expand All @@ -13,4 +13,4 @@ let () =
let response = Dream.response "Set language preference; come again!" in
Dream.add_header response "Content-Type" Dream.text_html;
Dream.set_cookie response request "ui.language" "ut-OP";
Lwt.return response
response
2 changes: 1 addition & 1 deletion example/c-cookie/dune
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
(executable
(name cookie)
(libraries dream))
(libraries dream eio_main))
3 changes: 1 addition & 2 deletions example/d-form/dune
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
(executable
(name form)
(libraries dream)
(preprocess (pps lwt_ppx)))
(libraries dream eio_main))

(rule
(targets form.ml)
Expand Down
6 changes: 3 additions & 3 deletions example/d-form/form.eml.ml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ let show_form ?message request =
</body>
</html>

let () =
Dream.run
let () = Eio_main.run @@ fun env ->
Dream.run env
@@ Dream.logger
@@ Dream.memory_sessions
@@ Dream.router [
Expand All @@ -28,7 +28,7 @@ let () =

Dream.post "/"
(fun request ->
match%lwt Dream.form request with
match Dream.form request with
| `Ok ["message", message] ->
Dream.html (show_form ~message request)
| _ ->
Expand Down
4 changes: 2 additions & 2 deletions example/e-json/dune
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(executable
(name json)
(libraries dream)
(preprocess (pps lwt_ppx ppx_yojson_conv)))
(libraries dream eio_main)
(preprocess (pps ppx_yojson_conv)))
8 changes: 3 additions & 5 deletions example/e-json/json.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@ type message_object = {
message : string;
} [@@deriving yojson]

let () =
Dream.run
let () = Eio_main.run @@ fun env ->
Dream.run env
@@ Dream.logger
@@ Dream.origin_referrer_check
@@ Dream.router [

Dream.post "/"
(fun request ->
let%lwt body = Dream.body request in

let message_object =
body
Dream.body request
|> Yojson.Safe.from_string
|> message_object_of_yojson
in
Expand Down
2 changes: 1 addition & 1 deletion example/f-static/dune
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
(executable
(name static)
(libraries dream))
(libraries dream eio_main))
6 changes: 3 additions & 3 deletions example/f-static/static.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
let () =
Dream.run
let () = Eio_main.run @@ fun env ->
Dream.run env
@@ Dream.logger
@@ Dream.router [
Dream.get "/static/**" (Dream.static ".")
Dream.get "/static/**" (Dream.static (Eio.Stdenv.cwd env))
]
1 change: 0 additions & 1 deletion src/cipher/dune
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@
mirage-crypto
mirage-crypto-rng
)
(preprocess (pps lwt_ppx))
(instrumentation (backend bisect_ppx)))
13 changes: 0 additions & 13 deletions src/cipher/random.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,7 @@



(* TODO LATER Is there something with lighter dependencies? Although perhaps
these are not so bad... *)

let _initialized : unit lazy_t option ref = ref None

let initialized () =
match !_initialized with
| None -> failwith "Entropy is not initialized."
| Some v -> Lazy.force v

let initialize f = _initialized := Some (Lazy.from_fun f)

let random_buffer n =
initialized () ;
Mirage_crypto_rng.generate n

let random n =
Expand Down
Loading
Loading