Skip to content

Commit

Permalink
Remove deprecated values
Browse files Browse the repository at this point in the history
Path getter and setter not removed. See #238. not_found just deprecated,
so not removed, for users to have more of a chance to adapt.
  • Loading branch information
aantron committed May 11, 2023
1 parent 14093e1 commit e14bd91
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 246 deletions.
46 changes: 0 additions & 46 deletions src/dream.ml
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,6 @@ let verify_csrf_token = Csrf.verify_csrf_token ~now

(* Templates *)

let form_tag ?method_ ?target ?enctype ?csrf_token ~action request =
Tag.form_tag ~now ?method_ ?target ?enctype ?csrf_token ~action request

let csrf_tag = Tag.csrf_tag ~now


Expand Down Expand Up @@ -274,7 +271,6 @@ let session_expires_at = Session.session_expires_at

let flash = Flash.flash_messages
let flash_messages = Flash.flash
let put_flash = Flash.put_flash
let add_flash_message = Flash.put_flash


Expand Down Expand Up @@ -400,48 +396,6 @@ let echo = Echo.echo

(* Deprecated helpers. *)

let with_client client message =
Helpers.set_client message client;
message

let with_method_ method_ message =
Message.set_method_ message method_;
message

let with_path path message =
Router.set_path message path;
message

let with_header name value message =
Message.set_header message name value;
message

let with_body body message =
Message.set_body message body;
message

let with_stream message =
message

let write_buffer ?(offset = 0) ?length message chunk =
let length =
match length with
| Some length -> length
| None -> Bigstringaf.length chunk - offset
in
let string = Bigstringaf.substring chunk ~off:offset ~len:length in
write (Message.server_stream message) string

type 'a local = 'a Message.field
let new_local = Message.new_field
let local = Message.field

let with_local key value message =
Message.set_field message key value;
message

let first message =
message

let last message =
message
169 changes: 0 additions & 169 deletions src/dream.mli
Original file line number Diff line number Diff line change
Expand Up @@ -386,25 +386,9 @@ https://github.com/aantron/dream/issues
val set_client : request -> string -> unit
(** Replaces the client. See {!Dream.val-client}. *)

(**/**)
val with_client : string -> request -> request
[@@ocaml.deprecated
"Use Dream.set_client. See
https://aantron.github.io/dream/#val-set_client
"]
(**/**)

val set_method_ : request -> [< method_ ] -> unit
(** Replaces the method. See {!Dream.type-method_}. *)

(**/**)
val with_method_ : [< method_ ] -> request -> request
[@@ocaml.deprecated
"Use Dream.set_method_. See
https://aantron.github.io/dream/#val-set_method_
"]
(**/**)

(**/**)
val with_path : string list -> request -> request
[@@ocaml.deprecated
Expand Down Expand Up @@ -533,14 +517,6 @@ val drop_header : 'a message -> string -> unit
val set_header : 'a message -> string -> string -> unit
(** Equivalent to {!Dream.drop_header} followed by {!Dream.add_header}. *)

(**/**)
val with_header : string -> string -> 'a message -> 'a message
[@@ocaml.deprecated
"Use Dream.set_header. See
https://aantron.github.io/dream/#val-with_header
"]
(**/**)



(** {1 Cookies}
Expand Down Expand Up @@ -704,14 +680,6 @@ val body : 'a message -> string promise
val set_body : 'a message -> string -> unit
(** Replaces the body. *)

(**/**)
val with_body : string -> response -> response
[@@ocaml.deprecated
"Use Dream.set_body. See
https://aantron.github.io/dream/#val-set_body
"]
(**/**)



(** {1 Streams} *)
Expand Down Expand Up @@ -749,14 +717,6 @@ val read : stream -> string option promise
(* TODO Document difference between receiving a request and receiving on a
WebSocket. *)

(**/**)
val with_stream : response -> response
[@@ocaml.deprecated
"Use Dream.stream instead. See
https://aantron.github.io/dream/#val-set_stream
"]
(**/**)

val write : stream -> string -> unit promise
(** Streams out the string. The promise is fulfilled when the response can
accept more writes. *)
Expand Down Expand Up @@ -868,15 +828,6 @@ val abort_stream : stream -> exn -> unit
(** Aborts the stream, causing all readers and writers to receive the given
exception. *)

(**/**)
val write_buffer :
?offset:int -> ?length:int -> response -> buffer -> unit promise
[@@ocaml.deprecated
"Use Dream.write_stream. See
https://aantron.github.io/dream/#val-write_stream
"]
(**/**)

(* TODO Ergonomics of this stream surface API. *)


Expand Down Expand Up @@ -1334,46 +1285,6 @@ val csrf_tag : request -> string
recommended} to put the CSRF tag immediately after the starting [<form>]
tag, to prevent certain kinds of DOM manipulation-based attacks. *)

(**/**)
val form_tag :
?method_:[< method_ ] ->
?target:string ->
?enctype:[< `Multipart_form_data ] ->
?csrf_token:bool ->
action:string -> request -> string
[@ocaml.deprecated
"Use Dream.csrf_tag. See
https://aantron.github.io/dream/#val-csrf_tag
"]
(** Generates a [<form>] tag and an [<input>] tag with a CSRF token, suitable
for use with {!Dream.val-form} and {!Dream.val-multipart}. For example, in
a template,
{[
<%s! Dream.form_tag ~action:"/" request %>
<input name="my.field">
</form>
]}
expands to
{[
<form method="POST" action="/">
<input name="dream.csrf" type="hidden" value="a-token">
<input name="my.field">
</form>
]}
[~method] sets the method used to submit the form. The default is [`POST].
[~target] adds a [target] attribute. For example, [~target:"_blank"] causes
the browser to submit the form in a new tab or window.
Pass [~enctype:`Multipart_form_data] for a file upload form.
[~csrf_token:false] suppresses generation of the [dream.csrf] field. *)
(**/**)



(** {1 Middleware}
Expand Down Expand Up @@ -1646,37 +1557,13 @@ val mime_lookup : string -> (string * string) list
val session_field : request -> string -> string option
(** Value from the request's session. *)

(**/**)
val session : string -> request -> string option
[@ocaml.deprecated
"Renamed to Dream.session_field. See
https://aantron.github.io/dream/#val-session_field
"]
(**/**)

val set_session_field : request -> string -> string -> unit promise
(** Mutates a value in the request's session. The back end may commit the value
to storage immediately, so this function returns a promise. *)

(**/**)
val put_session : string -> string -> request -> unit promise
[@ocaml.deprecated
"Renamed to Dream.set_session_field. See
https://aantron.github.io/dream/#val-set_session_field
"]
(**/**)

val all_session_fields : request -> (string * string) list
(** Full session dictionary. *)

(**/**)
val all_session_values : request -> (string * string) list
[@ocaml.deprecated
"Renamed to Dream.all_session_fields. See
https://aantron.github.io/dream/#val-all_session_fields
"]
(**/**)

val invalidate_session : request -> unit promise
(** Invalidates the request's session, replacing it with a fresh, empty
pre-session. *)
Expand Down Expand Up @@ -1734,14 +1621,6 @@ val flash_messages : request -> (string * string) list
val add_flash_message : request -> string -> string -> unit
(** Adds a flash message to the request. *)

(**/**)
val put_flash : request -> string -> string -> unit
[@@ocaml.deprecated
"Renamed to Dream.add_flash_message. See
https://aantron.github.io/dream/#val-add_flash_message
"]
(**/**)



(** {1 GraphQL}
Expand Down Expand Up @@ -2513,49 +2392,17 @@ val decrypt :
type 'a field
(** Per-message variable. *)

(**/**)
type 'a local = 'a field
[@@ocaml.deprecated
"Renamed to type Dream.field. See
https://aantron.github.io/dream/#type-field
"]
(**/**)

val new_field : ?name:string -> ?show_value:('a -> string) -> unit -> 'a field
(** Declares a variable of type ['a] in all messages. The variable is initially
unset in each message. The optional [~name] and [~show_value] are used by
{!Dream.run} [~debug] to show the variable in debug dumps. *)

(**/**)
val new_local : ?name:string -> ?show_value:('a -> string) -> unit -> 'a field
[@@ocaml.deprecated
"Renamed to Dream.new_field. See
https://aantron.github.io/dream/#val-new_field
"]
(**/**)

val field : 'b message -> 'a field -> 'a option
(** Retrieves the value of the per-message variable. *)

(**/**)
val local : 'b message -> 'a field -> 'a option
[@@ocaml.deprecated
"Renamed to Dream.field. See
https://aantron.github.io/dream/#val-field
"]
(**/**)

val set_field : 'b message -> 'a field -> 'a -> unit
(** Sets the per-message variable to the value. *)

(**/**)
val with_local : 'a field -> 'a -> 'b message -> 'b message
[@@ocaml.deprecated
"Use Dream.set_field instead. See
https://aantron.github.io/dream/#val-set_field
"]
(**/**)



(** {1 Testing} *)
Expand All @@ -2578,22 +2425,6 @@ val test : ?prefix:string -> handler -> (request -> response)
the test is not wrapped in a promise. If you don't need these facilities,
you can test [handler] by calling it directly with a request. *)

(**/**)
val first : 'a message -> 'a message
[@@ocaml.deprecated "Simply returns its own argument."]
(** [Dream.first message] evaluates to the original request or response that
[message] is immutably derived from. This is useful for getting the original
state of requests especially, when they were first created inside the HTTP
server ({!Dream.run}). *)

val last : 'a message -> 'a message
[@@ocaml.deprecated "Simply returns its own argument."]
(** [Dream.last message] evaluates to the latest request or response that was
derived from [message]. This is most useful for obtaining the state of
requests at the time an exception was raised, without having to instrument
the latest version of the request before the exception. *)
(**/**)

val sort_headers : (string * string) list -> (string * string) list
(** Sorts headers by name. Headers with the same name are not sorted by value or
otherwise reordered, because order is significant for some headers. See
Expand Down
31 changes: 0 additions & 31 deletions src/server/tag.eml.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,3 @@ module Method = Dream_pure.Method
let csrf_tag ~now request =
let token = Csrf.csrf_token ~now request in
<input name="<%s! Csrf.field_name %>" type="hidden" value="<%s! token %>">

(* TODO Include the path prefix. *)
let form_tag
~now ?method_ ?target ?enctype ?csrf_token ~action request =

let method_ =
match method_ with
| None -> Method.method_to_string `POST
| Some method_ -> Method.method_to_string method_
in
let target =
match target with
| Some target -> " target=\"" ^ Dream.html_escape target ^ "\""
| None -> ""
in
let enctype =
match enctype with
| Some `Multipart_form_data -> " enctype=\"multipart/form-data\""
| None -> ""
in
let csrf_token =
match csrf_token with
| None -> true
| Some csrf_token -> csrf_token
in
<form
method="<%s! method_ %>"
action="<%s action %>"<%s! target %><%s! enctype %>>
% if csrf_token then begin
<%s! csrf_tag ~now request %>
% end;

0 comments on commit e14bd91

Please sign in to comment.