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

Wrap vendored modules to avoid build conflicts #250

Merged
merged 2 commits into from
Mar 13, 2023
Merged
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
3 changes: 3 additions & 0 deletions src/http/adapt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@



module Httpaf = Dream_httpaf_.Httpaf
module H2 = Dream_h2.H2

module Stream = Dream_pure.Stream
module Message = Dream_pure.Message

Expand Down
14 changes: 7 additions & 7 deletions src/http/dune
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
4 changes: 4 additions & 0 deletions src/http/error_handler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/http/error_handler.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions src/http/http.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/http/shared/dune
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
(libraries
bigstringaf
dream-pure
dream-httpaf.websocketaf
dream-httpaf.dream-websocketaf
)
(preprocess (pps lwt_ppx))
(instrumentation (backend bisect_ppx)))
2 changes: 2 additions & 0 deletions src/http/shared/websocket.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@



module Websocketaf = Dream_websocketaf.Websocketaf

module Stream = Dream_pure.Stream


Expand Down
3 changes: 3 additions & 0 deletions src/mirage/adapt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions src/mirage/dune
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
55 changes: 28 additions & 27 deletions src/mirage/error_handler.ml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module Httpaf = Dream_httpaf_.Httpaf

module Catch = Dream__server.Catch
module Error_template = Dream__server.Error_template
Expand All @@ -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"
Expand All @@ -49,40 +50,40 @@ 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"
| `Warning -> "Warning"
| `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";
Expand All @@ -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]
Expand All @@ -117,34 +118,34 @@ let select_log = function
| `WebSocket -> ["WebSocket" ^ client]
| `App -> []
in

let description, backtrace =
match condition with
| `String string -> string, ""
| `Exn exn ->
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
Expand All @@ -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. *)
Expand All @@ -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

Expand Down Expand Up @@ -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)
4 changes: 4 additions & 0 deletions src/mirage/mirage.ml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Loading