Skip to content

Commit

Permalink
Rename ~https to ~tls
Browse files Browse the repository at this point in the history
  • Loading branch information
aantron committed Feb 11, 2022
1 parent 30ef880 commit 7320f87
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 38 deletions.
8 changes: 4 additions & 4 deletions docs/web/postprocess/index.ml
Expand Up @@ -1454,7 +1454,7 @@ let new_global_replacement = {|

let run_expected = {|<div class="spec value" id="val-run">
<a href="#val-run" class="anchor"></a><code><span><span class="keyword">val</span> run : <span>?interface:string <span class="arrow">-&gt;</span></span> <span>?port:int <span class="arrow">-&gt;</span></span> <span>?stop:<span>unit <a href="#type-promise">promise</a></span> <span class="arrow">-&gt;</span></span> <span>?error_handler:<a href="#type-error_handler">error_handler</a> <span class="arrow">-&gt;</span></span>
<span>?https:bool <span class="arrow">-&gt;</span></span> <span>?certificate_file:string <span class="arrow">-&gt;</span></span> <span>?key_file:string <span class="arrow">-&gt;</span></span> <span>?builtins:bool <span class="arrow">-&gt;</span></span>
<span>?tls:bool <span class="arrow">-&gt;</span></span> <span>?certificate_file:string <span class="arrow">-&gt;</span></span> <span>?key_file:string <span class="arrow">-&gt;</span></span> <span>?builtins:bool <span class="arrow">-&gt;</span></span>
<span>?greeting:bool <span class="arrow">-&gt;</span></span> <span>?adjust_terminal:bool <span class="arrow">-&gt;</span></span> <span><a href="#type-handler">handler</a> <span class="arrow">-&gt;</span></span> unit</span></code>
</div>
|}
Expand All @@ -1468,7 +1468,7 @@ let run_replacement = {|
?secret:string ->
?old_secrets:string list ->
?prefix:string ->
?https:true ->
?tls:bool ->
?certificate_file:string ->
?key_file:string ->
?builtins:bool ->
Expand All @@ -1479,7 +1479,7 @@ let run_replacement = {|

let serve_expected = {|<div class="spec value" id="val-serve">
<a href="#val-serve" class="anchor"></a><code><span><span class="keyword">val</span> serve : <span>?interface:string <span class="arrow">-&gt;</span></span> <span>?port:int <span class="arrow">-&gt;</span></span> <span>?stop:<span>unit <a href="#type-promise">promise</a></span> <span class="arrow">-&gt;</span></span> <span>?error_handler:<a href="#type-error_handler">error_handler</a> <span class="arrow">-&gt;</span></span>
<span>?https:bool <span class="arrow">-&gt;</span></span> <span>?certificate_file:string <span class="arrow">-&gt;</span></span> <span>?key_file:string <span class="arrow">-&gt;</span></span> <span>?builtins:bool <span class="arrow">-&gt;</span></span>
<span>?tls:bool <span class="arrow">-&gt;</span></span> <span>?certificate_file:string <span class="arrow">-&gt;</span></span> <span>?key_file:string <span class="arrow">-&gt;</span></span> <span>?builtins:bool <span class="arrow">-&gt;</span></span>
<span><a href="#type-handler">handler</a> <span class="arrow">-&gt;</span></span> <span>unit <a href="#type-promise">promise</a></span></span></code>
</div>
|}
Expand All @@ -1493,7 +1493,7 @@ let serve_replacement = {|
?secret:string ->
?old_secrets:string list ->
?prefix:string ->
?https:bool ->
?tls:bool ->
?certificate_file:string ->
?key_string:string ->
?builtins:bool -></span>
Expand Down
2 changes: 1 addition & 1 deletion example/8-debug/README.md
Expand Up @@ -63,7 +63,7 @@ Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9,ru-RU;q=0.8,ru;q=0.7
dream.client: 127.0.0.1:64687
dream.https: false
dream.tls: false
dream.request_id: 3
dream.params:
```
Expand Down
2 changes: 1 addition & 1 deletion src/dream.ml
Expand Up @@ -96,7 +96,7 @@ include Status
(* Requests *)

let client = Helpers.client
let https = Helpers.https
let tls = Helpers.tls
let method_ = Message.method_
let target = Message.target
let prefix = Router.prefix
Expand Down
18 changes: 9 additions & 9 deletions src/dream.mli
Expand Up @@ -360,8 +360,8 @@ val normalize_status : [< status ] -> status
val client : request -> string
(** Client sending the request. For example, ["127.0.0.1:56001"]. *)

val https : request -> bool
(** Whether the request was sent over HTTPS. *)
val tls : request -> bool
(** Whether the request was sent over a TLS connection. *)

val method_ : request -> method_
(** Request method. For example, [`GET]. *)
Expand Down Expand Up @@ -651,7 +651,7 @@ val set_cookie :
{{:https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#Path_attribute}
MDN}.
- [~secure] sets the [Secure] attribute. By default, [Secure] is set if
{!Dream.https} is [true] for the {!type-request}. See
{!Dream.tls} is [true] for the {!type-request}. See
{{:https://tools.ietf.org/html/draft-ietf-httpbis-rfc6265bis-07#section-4.1.2.5}
RFC 6265bis §4.1.2.5} and
{{:https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#restrict_access_to_cookies}
Expand Down Expand Up @@ -2208,7 +2208,7 @@ val run :
?port:int ->
?stop:unit promise ->
?error_handler:error_handler ->
?https:bool ->
?tls:bool ->
?certificate_file:string ->
?key_file:string ->
?builtins:bool ->
Expand Down Expand Up @@ -2238,18 +2238,18 @@ val run :
low-level errors. See {!section-errors} and example
{{:https://github.com/aantron/dream/tree/master/example/9-error#files}
[9-error]} \[{{:http://dream.as/9-error} playground}\].
- [~https:true] enables HTTPS. You should also specify [~certificate_file]
and [~key_file]. However, for development, Dream includes an insecure
- [~tls:true] enables TLS. You should also specify [~certificate_file] and
[~key_file]. However, for development, Dream includes an insecure
compiled-in
{{:https://github.com/aantron/dream/tree/master/src/certificate#files}
localhost certificate}. Enabling HTTPS also enables transparent upgrading
of connections to HTTP/2. See example
{{:https://github.com/aantron/dream/tree/master/example/l-https#files}
[l-https]}.
- [~certificate_file] and [~key_file] specify the certificate and key file,
respectively, when using [~https]. They are not required for development,
respectively, when using [~tls]. They are not required for development,
but are required for production. Dream will write a warning to the log if
you are using [~https], don't provide [~certificate_file] and [~key_file],
you are using [~tls], don't provide [~certificate_file] and [~key_file],
and [~interface] is not ["localhost"].
- [~builtins:false] disables {!section-builtin}.
Expand All @@ -2267,7 +2267,7 @@ val serve :
?port:int ->
?stop:unit promise ->
?error_handler:error_handler ->
?https:bool ->
?tls:bool ->
?certificate_file:string ->
?key_file:string ->
?builtins:bool ->
Expand Down
22 changes: 11 additions & 11 deletions src/http/http.ml
Expand Up @@ -52,7 +52,7 @@ let websocket_log =
chance to tell the user that something is wrong with their app. *)
(* TODO Rename conn like in the body branch. *)
let wrap_handler
https
tls
(user's_error_handler : Catch.error_handler)
(user's_dream_handler : Message.handler) =

Expand Down Expand Up @@ -96,7 +96,7 @@ let wrap_handler
Stream.stream body Stream.no_writer in

let request : Message.request =
Helpers.request ~client ~method_ ~target ~https ~version ~headers body in
Helpers.request ~client ~method_ ~target ~tls ~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 @@ -188,7 +188,7 @@ let wrap_handler

(* TODO Factor out what is in common between the http/af and h2 handlers. *)
let wrap_handler_h2
https
tls
(_user's_error_handler : Catch.error_handler)
(user's_dream_handler : Message.handler) =

Expand Down Expand Up @@ -226,7 +226,7 @@ let wrap_handler_h2
Stream.stream body Stream.no_writer in

let request : Message.request =
Helpers.request ~client ~method_ ~target ~https ~version ~headers body in
Helpers.request ~client ~method_ ~target ~tls ~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 @@ -483,7 +483,7 @@ let serve_with_maybe_https
~port
~stop
~error_handler
~https
~tls
?certificate_file ?key_file
?certificate_string ?key_string
~builtins
Expand All @@ -500,7 +500,7 @@ let serve_with_maybe_https
end; *)
(* TODO Make sure there is a similar check in cipher.ml now.Hpack *)

match https with
match tls with
| `No ->
serve_with_details
caller_function_for_error_messages
Expand Down Expand Up @@ -632,7 +632,7 @@ let serve
?(port = default_port)
?(stop = never)
?(error_handler = Error_handler.default)
?(https = false)
?(tls = false)
?certificate_file
?key_file
?(builtins = true)
Expand All @@ -644,7 +644,7 @@ let serve
~port
~stop
~error_handler
~https:(if https then `OpenSSL else `No)
~tls:(if tls then `OpenSSL else `No)
?certificate_file
?key_file
?certificate_string:None
Expand All @@ -659,7 +659,7 @@ let run
?(port = default_port)
?(stop = never)
?(error_handler = Error_handler.default)
?(https = false)
?(tls = false)
?certificate_file
?key_file
?(builtins = true)
Expand Down Expand Up @@ -713,7 +713,7 @@ let run

if greeting then begin
let scheme =
if https then
if tls then
"https"
else
"http"
Expand All @@ -736,7 +736,7 @@ let run
~port
~stop
~error_handler
~https:(if https then `OpenSSL else `No)
~tls:(if tls then `OpenSSL else `No)
?certificate_file ?key_file
?certificate_string:None ?key_string:None
~builtins
Expand Down
4 changes: 2 additions & 2 deletions src/server/cookie.ml
Expand Up @@ -56,7 +56,7 @@ let cookie
let secure =
match secure with
| Some secure -> secure
| None -> Helpers.https request
| None -> Helpers.tls request
in

let cookie_prefix = infer_cookie_prefix cookie_prefix domain path secure in
Expand Down Expand Up @@ -100,7 +100,7 @@ let set_cookie
let secure =
match secure with
| Some secure -> secure
| None -> Helpers.https request
| None -> Helpers.tls request
in

let cookie_prefix = infer_cookie_prefix cookie_prefix domain path secure in
Expand Down
16 changes: 8 additions & 8 deletions src/server/helpers.ml
Expand Up @@ -30,28 +30,28 @@ let set_client request client =



let https_field =
let tls_field =
Message.new_field
~name:"dream.https"
~name:"dream.tls"
~show_value:string_of_bool
()

let https request =
match Message.field request https_field with
let tls request =
match Message.field request tls_field with
| Some true -> true
| _ -> false

let set_https request https =
Message.set_field request https_field https
let set_tls request tls =
Message.set_field request tls_field tls



let request ~client ~method_ ~target ~https ~version ~headers server_stream =
let request ~client ~method_ ~target ~tls ~version ~headers server_stream =
let request =
Message.request
~method_ ~target ~version ~headers Stream.null server_stream in
set_client request client;
set_https request https;
set_tls request tls;
request

let request_with_body ?method_ ?target ?version ?headers body =
Expand Down
4 changes: 2 additions & 2 deletions src/server/origin_referrer_check.ml
Expand Up @@ -49,8 +49,8 @@ let origin_referrer_check inner_handler request =

let schemes_match =
match Uri.scheme origin_uri with
| Some "http" -> not (Helpers.https request)
| Some "https" -> Helpers.https request
| Some "http" -> not (Helpers.tls request)
| Some "https" -> Helpers.tls request
| _ -> false
in

Expand Down

0 comments on commit 7320f87

Please sign in to comment.