Skip to content

Commit

Permalink
add support for providing an httpaf configuration when starting/runni…
Browse files Browse the repository at this point in the history
…ng dream, temporarily works around aantron#214
  • Loading branch information
cemerick committed Apr 22, 2023
1 parent a39c938 commit b73c882
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/dream.mli
Original file line number Diff line number Diff line change
Expand Up @@ -2200,6 +2200,7 @@ val run :
?tls:bool ->
?certificate_file:string ->
?key_file:string ->
?httpaf_config:Dream_httpaf_.Httpaf.Config.t ->
?builtins:bool ->
?greeting:bool ->
?adjust_terminal:bool ->
Expand Down Expand Up @@ -2240,6 +2241,9 @@ val run :
but are required for production. Dream will write a warning to the log if
you are using [~tls], don't provide [~certificate_file] and [~key_file],
and [~interface] is not ["localhost"].
- [~httpaf_config] is an [Httpaf.Config.t] value that is passed along to
Httpaf to control buffer sizes used when parsing and building
e.g. websocket messages
- [~builtins:false] disables {!section-builtin}.
The remaining arguments can be used to gradually disable convenience
Expand All @@ -2259,6 +2263,7 @@ val serve :
?tls:bool ->
?certificate_file:string ->
?key_file:string ->
?httpaf_config:Dream_httpaf_.Httpaf.Config.t ->
?builtins:bool ->
handler -> unit promise
(** Like {!Dream.run}, but returns a promise that does not resolve until the
Expand Down
23 changes: 19 additions & 4 deletions src/http/http.ml
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ type tls_library = {
create_handler :
certificate_file:string ->
key_file:string ->
httpaf_config:Httpaf.Config.t ->
handler:Message.handler ->
error_handler:Catch.error_handler ->
Unix.sockaddr ->
Expand All @@ -300,10 +301,12 @@ type tls_library = {
let no_tls = {
create_handler = begin fun
~certificate_file:_ ~key_file:_
~httpaf_config
~handler
~error_handler ->
~error_handler
->
Httpaf_lwt_unix.Server.create_connection_handler
?config:None
~config:httpaf_config
~request_handler:(wrap_handler false error_handler handler)
~error_handler:(Error_handler.httpaf error_handler)
end;
Expand All @@ -312,12 +315,13 @@ let no_tls = {
let openssl = {
create_handler = begin fun
~certificate_file ~key_file
~httpaf_config
~handler
~error_handler ->

let httpaf_handler =
Httpaf_lwt_unix.Server.SSL.create_connection_handler
?config:None
~config:httpaf_config
~request_handler:(wrap_handler true error_handler handler)
~error_handler:(Error_handler.httpaf error_handler)
in
Expand Down Expand Up @@ -371,11 +375,12 @@ let openssl = {
let ocaml_tls = {
create_handler = fun
~certificate_file ~key_file
~httpaf_config
~handler
~error_handler ->
Httpaf_lwt_unix.Server.TLS.create_connection_handler_with_default
~certfile:certificate_file ~keyfile:key_file
?config:None
~config:httpaf_config
~request_handler:(wrap_handler true error_handler handler)
~error_handler:(Error_handler.httpaf error_handler)
}
Expand All @@ -399,6 +404,7 @@ let serve_with_details
~certificate_file
~key_file
~builtins
~httpaf_config
user's_dream_handler =

(* TODO DOC *)
Expand All @@ -416,6 +422,7 @@ let serve_with_details
tls_library.create_handler
~certificate_file
~key_file
~httpaf_config
~handler:user's_dream_handler
~error_handler
in
Expand Down Expand Up @@ -483,6 +490,7 @@ let serve_with_maybe_https
~tls
?certificate_file ?key_file
?certificate_string ?key_string
~httpaf_config
~builtins
user's_dream_handler =

Expand All @@ -509,6 +517,7 @@ let serve_with_maybe_https
~certificate_file:""
~key_file:""
~builtins
~httpaf_config
user's_dream_handler

| `OpenSSL | `OCaml_TLS as tls_library ->
Expand Down Expand Up @@ -574,6 +583,7 @@ let serve_with_maybe_https
~certificate_file
~key_file
~builtins
~httpaf_config
user's_dream_handler

| `Memory (certificate_string, key_string, verbose_or_silent) ->
Expand Down Expand Up @@ -602,6 +612,7 @@ let serve_with_maybe_https
~certificate_file
~key_file
~builtins
~httpaf_config
user's_dream_handler

end
Expand Down Expand Up @@ -632,6 +643,7 @@ let serve
?(tls = false)
?certificate_file
?key_file
?(httpaf_config = Httpaf.Config.default)
?(builtins = true)
user's_dream_handler =

Expand All @@ -646,6 +658,7 @@ let serve
?key_file
?certificate_string:None
?key_string:None
~httpaf_config
~builtins
user's_dream_handler

Expand All @@ -659,6 +672,7 @@ let run
?(tls = false)
?certificate_file
?key_file
?(httpaf_config = Httpaf.Config.default)
?(builtins = true)
?(greeting = true)
?(adjust_terminal = true)
Expand Down Expand Up @@ -736,6 +750,7 @@ let run
~tls:(if tls then `OpenSSL else `No)
?certificate_file ?key_file
?certificate_string:None ?key_string:None
~httpaf_config
~builtins
user's_dream_handler
end;
Expand Down

0 comments on commit b73c882

Please sign in to comment.