Skip to content

Commit

Permalink
Move the https field to requests
Browse files Browse the repository at this point in the history
  • Loading branch information
aantron committed Dec 13, 2021
1 parent ebeac7c commit 6c726d5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
16 changes: 8 additions & 8 deletions src/http/http.ml
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ let websocket_handler user's_websocket_handler socket =
(* TODO Rename conn like in the body branch. *)
let wrap_handler
app
https
(user's_error_handler : Dream.error_handler)
(user's_dream_handler : Dream.handler) =

Expand Down Expand Up @@ -338,7 +339,7 @@ let wrap_handler

let request : Dream.request =
Dream.request_from_http
~app ~client ~method_ ~target ~version ~headers body in
~app ~client ~method_ ~target ~https ~version ~headers body in

(* Call the user's handler. If it raises an exception or returns a promise
that rejects with an exception, pass the exception up to Httpaf. This
Expand Down Expand Up @@ -445,6 +446,7 @@ let wrap_handler
(* TODO Factor out what is in common between the http/af and h2 handlers. *)
let wrap_handler_h2
app
https
(_user's_error_handler : Dream.error_handler)
(user's_dream_handler : Dream.handler) =

Expand Down Expand Up @@ -483,7 +485,7 @@ let wrap_handler_h2

let request : Dream.request =
Dream.request_from_http
~app ~client ~method_ ~target ~version ~headers body in
~app ~client ~method_ ~target ~https ~version ~headers body in

(* Call the user's handler. If it raises an exception or returns a promise
that rejects with an exception, pass the exception up to Httpaf. This
Expand Down Expand Up @@ -566,7 +568,7 @@ let no_tls = {
~error_handler ->
Httpaf_lwt_unix.Server.create_connection_handler
?config:None
~request_handler:(wrap_handler app error_handler handler)
~request_handler:(wrap_handler app false error_handler handler)
~error_handler:(Error_handler.httpaf app error_handler)
end;
}
Expand All @@ -581,14 +583,14 @@ let openssl = {
let httpaf_handler =
Httpaf_lwt_unix.Server.SSL.create_connection_handler
?config:None
~request_handler:(wrap_handler app error_handler handler)
~request_handler:(wrap_handler app true error_handler handler)
~error_handler:(Error_handler.httpaf app error_handler)
in

let h2_handler =
H2_lwt_unix.Server.SSL.create_connection_handler
?config:None
~request_handler:(wrap_handler_h2 app error_handler handler)
~request_handler:(wrap_handler_h2 app true error_handler handler)
~error_handler:(Error_handler.h2 app error_handler)
in

Expand Down Expand Up @@ -640,7 +642,7 @@ let ocaml_tls = {
Httpaf_lwt_unix.Server.TLS.create_connection_handler_with_default
~certfile:certificate_file ~keyfile:key_file
?config:None
~request_handler:(wrap_handler app error_handler handler)
~request_handler:(wrap_handler app true error_handler handler)
~error_handler:(Error_handler.httpaf app error_handler)
}

Expand Down Expand Up @@ -789,8 +791,6 @@ let serve_with_maybe_https
user's_dream_handler

| `OpenSSL | `OCaml_TLS as tls_library ->
Dream.set_https true app;

(* TODO Writing temporary files is extremely questionable for anything
except the fake localhost certificate. This needs loud warnings. IIRC
the SSL binding already supports in-memory certificates. Does TLS? In
Expand Down
2 changes: 1 addition & 1 deletion src/pure/dream_pure.mli
Original file line number Diff line number Diff line change
Expand Up @@ -406,12 +406,12 @@ val app : request -> app
val debug : app -> bool
val set_debug : bool -> app -> unit
val app_error_handler : app -> (error -> response promise)
val set_https : bool -> app -> unit
val request_from_http :
app:app ->
client:string ->
method_:method_ ->
target:string ->
https:bool ->
version:int * int ->
headers:(string * string) list ->
stream ->
Expand Down
11 changes: 5 additions & 6 deletions src/pure/inmost.ml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ and client = {
prefix : string list;
path : string list;
query : (string * string) list;
https : bool;
request_version : int * int;
upload : multipart_state;
}
Expand All @@ -71,7 +72,6 @@ and server = {

and app = {
mutable app_debug : bool;
mutable https : bool;
error_handler : error -> response Lwt.t;
}

Expand Down Expand Up @@ -125,12 +125,8 @@ let set_debug value app =
let app_error_handler app =
app.error_handler

let set_https https app =
app.https <- https

let new_app error_handler = {
app_debug = false;
https = false;
error_handler;
}

Expand All @@ -153,7 +149,7 @@ let client request =
request.specific.request_client

let https request =
request.specific.app.https
request.specific.https

let method_ request =
request.specific.method_
Expand Down Expand Up @@ -419,6 +415,7 @@ let request_from_http
~client
~method_
~target
~https
~version
~headers
body =
Expand All @@ -434,6 +431,7 @@ let request_from_http
prefix = [];
path = Formats.from_path path;
query = Formats.from_form_urlencoded query;
https;
request_version = version;
upload = initial_multipart_state ();
};
Expand Down Expand Up @@ -477,6 +475,7 @@ let request
prefix = [];
path = Formats.from_path path;
query = Formats.from_form_urlencoded query;
https = false;
request_version = version;
upload = initial_multipart_state ();
};
Expand Down

0 comments on commit 6c726d5

Please sign in to comment.