From c8d2db0f637c9c8902c69648038b81bde78b14ec Mon Sep 17 00:00:00 2001 From: Anton Bachin Date: Fri, 10 Mar 2023 14:15:03 +0300 Subject: [PATCH 1/2] Rename vendored modules to avoid build conflicts Fixes #198. Closes #200. --- src/http/adapt.ml | 3 ++ src/http/dune | 14 +++--- src/http/error_handler.ml | 4 ++ src/http/error_handler.mli | 4 ++ src/http/http.ml | 8 +++ src/http/shared/dune | 2 +- src/http/shared/websocket.ml | 2 + src/vendor/dune | 96 ++++++++++++++++++------------------ src/vendor/gluten | 2 +- src/vendor/h2 | 2 +- src/vendor/httpaf | 2 +- src/vendor/websocketaf | 2 +- 12 files changed, 81 insertions(+), 60 deletions(-) diff --git a/src/http/adapt.ml b/src/http/adapt.ml index 34aeb6ff..8f822c0b 100644 --- a/src/http/adapt.ml +++ b/src/http/adapt.ml @@ -5,6 +5,9 @@ +module Httpaf = Dream_httpaf_.Httpaf +module H2 = Dream_h2.H2 + module Stream = Dream_pure.Stream module Message = Dream_pure.Message diff --git a/src/http/dune b/src/http/dune index cac581f3..76ddb65e 100644 --- a/src/http/dune +++ b/src/http/dune @@ -8,17 +8,17 @@ dream-pure dream.server dream-httpaf - dream-httpaf.gluten - dream-httpaf.gluten-lwt-unix - dream-httpaf.h2 - dream-httpaf.h2-lwt-unix - dream-httpaf.httpaf - dream-httpaf.httpaf-lwt-unix + dream-httpaf.dream-gluten + dream-httpaf.dream-gluten-lwt-unix + dream-httpaf.dream-h2 + dream-httpaf.dream-h2-lwt-unix + dream-httpaf.dream-httpaf_ + dream-httpaf.dream-httpaf_-lwt-unix lwt lwt.unix lwt_ssl ssl - dream-httpaf.websocketaf + dream-httpaf.dream-websocketaf ) (preprocess (pps lwt_ppx)) (instrumentation (backend bisect_ppx))) diff --git a/src/http/error_handler.ml b/src/http/error_handler.ml index e24c28a4..d371ea75 100644 --- a/src/http/error_handler.ml +++ b/src/http/error_handler.ml @@ -5,6 +5,10 @@ +module Httpaf = Dream_httpaf_.Httpaf +module H2 = Dream_h2.H2 +module Websocketaf = Dream_websocketaf.Websocketaf + module Catch = Dream__server.Catch module Error_template = Dream__server.Error_template module Method = Dream_pure.Method diff --git a/src/http/error_handler.mli b/src/http/error_handler.mli index 285469b5..f2a06390 100644 --- a/src/http/error_handler.mli +++ b/src/http/error_handler.mli @@ -5,6 +5,10 @@ +module Httpaf = Dream_httpaf_.Httpaf +module H2 = Dream_h2.H2 +module Websocketaf = Dream_websocketaf.Websocketaf + module Catch = Dream__server.Catch module Log = Dream__server.Log module Message = Dream_pure.Message diff --git a/src/http/http.ml b/src/http/http.ml index 85414dc3..10d56902 100644 --- a/src/http/http.ml +++ b/src/http/http.ml @@ -5,6 +5,14 @@ +module Gluten = Dream_gluten.Gluten +module Gluten_lwt_unix = Dream_gluten_lwt_unix.Gluten_lwt_unix +module Httpaf = Dream_httpaf_.Httpaf +module Httpaf_lwt_unix = Dream_httpaf__lwt_unix.Httpaf_lwt_unix +module H2 = Dream_h2.H2 +module H2_lwt_unix = Dream_h2_lwt_unix.H2_lwt_unix +module Websocketaf = Dream_websocketaf.Websocketaf + module Catch = Dream__server.Catch module Helpers = Dream__server.Helpers module Log = Dream__server.Log diff --git a/src/http/shared/dune b/src/http/shared/dune index 07668721..31b3c06a 100644 --- a/src/http/shared/dune +++ b/src/http/shared/dune @@ -4,7 +4,7 @@ (libraries bigstringaf dream-pure - dream-httpaf.websocketaf + dream-httpaf.dream-websocketaf ) (preprocess (pps lwt_ppx)) (instrumentation (backend bisect_ppx))) diff --git a/src/http/shared/websocket.ml b/src/http/shared/websocket.ml index 0d4f6750..358d5774 100644 --- a/src/http/shared/websocket.ml +++ b/src/http/shared/websocket.ml @@ -5,6 +5,8 @@ +module Websocketaf = Dream_websocketaf.Websocketaf + module Stream = Dream_pure.Stream diff --git a/src/vendor/dune b/src/vendor/dune index 19a00e7f..cae56083 100644 --- a/src/vendor/dune +++ b/src/vendor/dune @@ -36,8 +36,8 @@ (subdir gluten/lib (library - (name gluten) - (public_name dream-httpaf.gluten) + (name dream_gluten) + (public_name dream-httpaf.dream-gluten) (libraries bigstringaf faraday @@ -45,19 +45,19 @@ (subdir gluten/lwt (library - (name gluten_lwt) - (public_name dream-httpaf.gluten-lwt) + (name dream_gluten_lwt) + (public_name dream-httpaf.dream-gluten-lwt) (libraries - dream-httpaf.gluten + dream-httpaf.dream-gluten lwt))) (subdir gluten/lwt-unix (library - (name gluten_lwt_unix) - (public_name dream-httpaf.gluten-lwt-unix) + (name dream_gluten_lwt_unix) + (public_name dream-httpaf.dream-gluten-lwt-unix) (libraries faraday-lwt-unix - dream-httpaf.gluten-lwt + dream-httpaf.dream-gluten-lwt lwt.unix (select ssl_io.ml @@ -75,44 +75,44 @@ (subdir websocketaf/lib (library - (name websocketaf) - (public_name dream-httpaf.websocketaf) + (name dream_websocketaf) + (public_name dream-httpaf.dream-websocketaf) (libraries angstrom base64 bigstringaf faraday - dream-httpaf.gluten - httpaf + dream-httpaf.dream-gluten + dream-httpaf.dream-httpaf_ result))) (subdir websocketaf/lwt (library - (name websocketaf_lwt) - (public_name dream-httpaf.websocketaf-lwt) + (name dream_websocketaf_lwt) + (public_name dream-httpaf.dream-websocketaf-lwt) (libraries base64 digestif.ocaml - dream-httpaf.gluten-lwt + dream-httpaf.dream-gluten-lwt lwt - dream-httpaf.websocketaf))) + dream-httpaf.dream-websocketaf))) (subdir websocketaf/lwt-unix (library - (name websocketaf_lwt_unix) - (public_name dream-httpaf.websocketaf-lwt-unix) + (name dream_websocketaf_lwt_unix) + (public_name dream-httpaf.dream-websocketaf-lwt-unix) (libraries faraday-lwt-unix - dream-httpaf.gluten-lwt-unix + dream-httpaf.dream-gluten-lwt-unix lwt.unix - dream-httpaf.websocketaf-lwt))) + dream-httpaf.dream-websocketaf-lwt))) (subdir httpaf/lib (library - (name httpaf) - (public_name dream-httpaf.httpaf) + (name dream_httpaf_) + (public_name dream-httpaf.dream-httpaf_) (libraries angstrom bigstringaf @@ -121,23 +121,23 @@ (subdir httpaf/lwt (library - (name httpaf_lwt) - (public_name dream-httpaf.httpaf-lwt) + (name dream_httpaf__lwt) + (public_name dream-httpaf.dream-httpaf_-lwt) (libraries - dream-httpaf.gluten - dream-httpaf.gluten-lwt - dream-httpaf.httpaf + dream-httpaf.dream-gluten + dream-httpaf.dream-gluten-lwt + dream-httpaf.dream-httpaf_ lwt))) (subdir httpaf/lwt-unix (library - (name httpaf_lwt_unix) - (public_name dream-httpaf.httpaf-lwt-unix) + (name dream_httpaf__lwt_unix) + (public_name dream-httpaf.dream-httpaf_-lwt-unix) (libraries faraday-lwt-unix - dream-httpaf.gluten-lwt-unix - dream-httpaf.httpaf - dream-httpaf.httpaf-lwt + dream-httpaf.dream-gluten-lwt-unix + dream-httpaf.dream-httpaf_ + dream-httpaf.dream-httpaf_-lwt lwt.unix))) @@ -150,8 +150,8 @@ (subdir h2/hpack/src (library - (name hpack) - (public_name dream-httpaf.hpack) + (name dream_hpack) + (public_name dream-httpaf.dream-hpack) (libraries angstrom faraday)) @@ -165,35 +165,35 @@ (subdir h2/lib (library - (name h2) - (public_name dream-httpaf.h2) + (name dream_h2) + (public_name dream-httpaf.dream-h2) (libraries angstrom base64 bigstringaf faraday - dream-httpaf.hpack - dream-httpaf.httpaf + dream-httpaf.dream-hpack + dream-httpaf.dream-httpaf_ psq result))) (subdir h2/lwt (library - (name h2_lwt) - (public_name dream-httpaf.h2-lwt) + (name dream_h2_lwt) + (public_name dream-httpaf.dream-h2-lwt) (libraries - dream-httpaf.gluten - dream-httpaf.gluten-lwt + dream-httpaf.dream-gluten + dream-httpaf.dream-gluten-lwt lwt - dream-httpaf.h2))) + dream-httpaf.dream-h2))) (subdir h2/lwt-unix (library - (name h2_lwt_unix) - (public_name dream-httpaf.h2-lwt-unix) + (name dream_h2_lwt_unix) + (public_name dream-httpaf.dream-h2-lwt-unix) (libraries faraday-lwt-unix - dream-httpaf.gluten-lwt-unix - dream-httpaf.h2 - dream-httpaf.h2-lwt + dream-httpaf.dream-gluten-lwt-unix + dream-httpaf.dream-h2 + dream-httpaf.dream-h2-lwt lwt.unix))) diff --git a/src/vendor/gluten b/src/vendor/gluten index f8b88c48..b2aea887 160000 --- a/src/vendor/gluten +++ b/src/vendor/gluten @@ -1 +1 @@ -Subproject commit f8b88c485beb473af97de7b39461fb60a56cff3f +Subproject commit b2aea88753540b4b315d9a242ccb2cdafd18dd91 diff --git a/src/vendor/h2 b/src/vendor/h2 index 2cc4f100..c372c736 160000 --- a/src/vendor/h2 +++ b/src/vendor/h2 @@ -1 +1 @@ -Subproject commit 2cc4f100455aea00911d773db4d6c1d7f11d42f5 +Subproject commit c372c736a278e3c5e4ea75adecb2cd400cedcdb1 diff --git a/src/vendor/httpaf b/src/vendor/httpaf index 7189cd28..340ba8c6 160000 --- a/src/vendor/httpaf +++ b/src/vendor/httpaf @@ -1 +1 @@ -Subproject commit 7189cd28e21203117f0c8e2347ae9a2fe0e0c157 +Subproject commit 340ba8c662a2b1cf3305cd46ad4eee65a6de9b7d diff --git a/src/vendor/websocketaf b/src/vendor/websocketaf index 44c54291..7530659c 160000 --- a/src/vendor/websocketaf +++ b/src/vendor/websocketaf @@ -1 +1 @@ -Subproject commit 44c54291a09ec271b256cdce3b3999315131c750 +Subproject commit 7530659c8a3fd1beed5197acde37dc7a20acd0af From c39461529350bbf975f34dd1ea5eb7866ed5c15b Mon Sep 17 00:00:00 2001 From: Anton Bachin Date: Mon, 13 Mar 2023 15:39:50 +0300 Subject: [PATCH 2/2] Continue renaming for Mirage version --- src/mirage/adapt.ml | 3 ++ src/mirage/dune | 8 +++--- src/mirage/error_handler.ml | 55 +++++++++++++++++++------------------ src/mirage/mirage.ml | 4 +++ src/vendor/dune | 23 ++++++++-------- src/vendor/paf | 2 +- 6 files changed, 51 insertions(+), 44 deletions(-) diff --git a/src/mirage/adapt.ml b/src/mirage/adapt.ml index 499a9d59..36ef4fee 100644 --- a/src/mirage/adapt.ml +++ b/src/mirage/adapt.ml @@ -6,6 +6,9 @@ XXX(dinosaure): same as [src/http/adapt.ml] without [address_to_string] - which depends on [Unix]. *) +module Httpaf = Dream_httpaf_.Httpaf +module H2 = Dream_h2.H2 + module Dream = Dream_pure module Stream = Dream_pure.Stream diff --git a/src/mirage/dune b/src/mirage/dune index 61f5ee3d..4cc14e8f 100644 --- a/src/mirage/dune +++ b/src/mirage/dune @@ -9,12 +9,12 @@ dream.server dream.certificate dream-pure - dream-httpaf.h2 + dream-httpaf.dream-h2 lwt tcpip - dream-mirage.paf - dream-mirage.paf.alpn - dream-mirage.paf.mirage + dream-mirage.dream-paf + dream-mirage.dream-paf.alpn + dream-mirage.dream-paf.mirage ) (preprocess (pps lwt_ppx)) (instrumentation (backend bisect_ppx))) diff --git a/src/mirage/error_handler.ml b/src/mirage/error_handler.ml index e8da12ec..958a01a8 100644 --- a/src/mirage/error_handler.ml +++ b/src/mirage/error_handler.ml @@ -1,3 +1,4 @@ +module Httpaf = Dream_httpaf_.Httpaf module Catch = Dream__server.Catch module Error_template = Dream__server.Error_template @@ -21,26 +22,26 @@ let select_log = function let dump (error : Catch.error) = let buffer = Buffer.create 4096 in let p format = Printf.bprintf buffer format in - + begin match error.condition with | `Response response -> let status = Message.status response in p "%i %s\n" (Status.status_to_int status) (Status.status_to_string status) - + | `String "" -> p "(Library error without description payload)\n" - + | `String string -> p "%s\n" string - + | `Exn exn -> let backtrace = Printexc.get_backtrace () in p "%s\n" (Printexc.to_string exn); backtrace |> Log.iter_backtrace (p "%s\n") end; - + p "\n"; - + let layer = match error.layer with | `TLS -> "TLS library" @@ -49,13 +50,13 @@ let select_log = function | `WebSocket -> "WebSocket library" | `App -> "Application" in - + let blame = match error.caused_by with | `Server -> "Server" | `Client -> "Client" in - + let severity = match error.severity with | `Error -> "Error" @@ -63,26 +64,26 @@ let select_log = function | `Info -> "Info" | `Debug -> "Debug" in - + p "From: %s\n" layer; p "Blame: %s\n" blame; p "Severity: %s" severity; - + begin match error.client with | None -> () | Some client -> p "\n\nClient: %s" client end; - + begin match error.request with | None -> () | Some request -> p "\n\n%s %s" (Method.method_to_string (Message.method_ request)) (Message.target request); - + Message.all_headers request |> List.iter (fun (name, value) -> p "\n%s: %s" name value); - + Message.fold_fields (fun name value first -> if first then p "\n"; @@ -92,23 +93,23 @@ let select_log = function request |> ignore end; - + Buffer.contents buffer let customize template (error : Catch.error) = (* First, log the error. *) - + begin match error.condition with | `Response _ -> () | `String _ | `Exn _ as condition -> - + let client = match error.client with | None -> "" | Some client -> " (" ^ client ^ ")" in - + let layer = match error.layer with | `TLS -> ["TLS" ^ client] @@ -117,7 +118,7 @@ let select_log = function | `WebSocket -> ["WebSocket" ^ client] | `App -> [] in - + let description, backtrace = match condition with | `String string -> string, "" @@ -125,26 +126,26 @@ let select_log = function let backtrace = Printexc.get_backtrace () in Printexc.to_string exn, backtrace in - + let message = String.concat ": " (layer @ [description]) in - + select_log error.severity (fun log -> log ?request:error.request "%s" message); backtrace |> Log.iter_backtrace (fun line -> select_log error.severity (fun log -> log ?request:error.request "%s" line)) end; - + (* If Dream will not send a response for this error, we are done after logging. Otherwise, if debugging is enabled, gather a bunch of information. Then, call the template, and return the response. *) - + if not error.will_send_response then Lwt.return_none - + else let debug_dump = dump error in - + let response = match error.condition with | `Response response -> response @@ -156,7 +157,7 @@ let select_log = function in Message.response ~status Stream.empty Stream.null in - + (* No need to catch errors when calling the template, because every call site of the error handler already has error handlers for catching double faults. *) @@ -168,7 +169,7 @@ let select_log = function Message.response ~status:`Internal_Server_Error Stream.empty Stream.null | `Client -> Message.response ~status:`Bad_Request Stream.empty Stream.null - + let default_template _error _debug_dump response = Lwt.return response @@ -241,7 +242,7 @@ let respond_with_option f = (fun () -> Message.response ~status:`Internal_Server_Error Stream.empty Stream.null |> Lwt.return) - + let app user's_error_handler = fun error -> respond_with_option (fun () -> user's_error_handler error) diff --git a/src/mirage/mirage.ml b/src/mirage/mirage.ml index f2c6bb9b..6f5f5a09 100644 --- a/src/mirage/mirage.ml +++ b/src/mirage/mirage.ml @@ -1,3 +1,7 @@ +module Httpaf = Dream_httpaf_.Httpaf +module Paf_mirage = Dream_paf_mirage.Paf_mirage +module Alpn = Dream_alpn.Alpn + module Catch = Dream__server.Catch module Error_template = Dream__server.Error_template module Method = Dream_pure.Method diff --git a/src/vendor/dune b/src/vendor/dune index cae56083..97aba743 100644 --- a/src/vendor/dune +++ b/src/vendor/dune @@ -4,32 +4,31 @@ (subdir paf/lib (library - (name paf) - (public_name dream-mirage.paf) + (name dream_paf) + (public_name dream-mirage.dream-paf) (modules paf) (libraries faraday bigstringaf ke mimic))) (subdir paf/lib (library - (name alpn) - (public_name dream-mirage.paf.alpn) + (name dream_alpn) + (public_name dream-mirage.dream-paf.alpn) (modules alpn) - (libraries dream-mirage.paf dream-httpaf.httpaf dream-httpaf.h2))) + (libraries dream-mirage.dream-paf dream-httpaf.dream-httpaf_ dream-httpaf.dream-h2))) (subdir paf/lib (library - (name paf_mirage) - (public_name dream-mirage.paf.mirage) + (name dream_paf_mirage) + (public_name dream-mirage.dream-paf.mirage) (modules paf_mirage) - (libraries tcpip dream-mirage.paf tls-mirage mirage-time dream-mirage.paf.alpn))) + (libraries tcpip dream-mirage.dream-paf tls-mirage mirage-time dream-mirage.dream-paf.alpn))) (subdir paf/lib (library - (name le) - (wrapped false) - (public_name dream-mirage.paf.le) + (name dream_le) + (public_name dream-mirage.dream-paf.le) (modules lE) - (libraries tcpip dream-httpaf.httpaf dream-mirage.paf mirage-time duration tls-mirage emile + (libraries tcpip dream-httpaf.httpaf dream-mirage.dream-paf mirage-time duration tls-mirage emile letsencrypt))) diff --git a/src/vendor/paf b/src/vendor/paf index 873e7b3b..14059ba8 160000 --- a/src/vendor/paf +++ b/src/vendor/paf @@ -1 +1 @@ -Subproject commit 873e7b3b00d60ac6d6b1a59c3e867f27f357369b +Subproject commit 14059ba85f886cf6babe9b8ce5a53a5b1f1bf3e8