Skip to content

Commit

Permalink
Delete request protocol version field
Browse files Browse the repository at this point in the history
  • Loading branch information
aantron committed Feb 13, 2022
1 parent 5f50acf commit 2162ec7
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 57 deletions.
5 changes: 0 additions & 5 deletions src/dream.ml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ let method_ = Message.method_
let target = Message.target
let prefix = Router.prefix
let path = Router.path
let version = Message.version
let set_client = Helpers.set_client
let set_method_ = Message.set_method_
let query = Query.query
Expand Down Expand Up @@ -408,10 +407,6 @@ let with_method_ method_ message =
Message.set_method_ message method_;
message

let with_version version message =
Message.set_version message version;
message

let with_path path message =
Router.set_path message path;
message
Expand Down
19 changes: 0 additions & 19 deletions src/dream.mli
Original file line number Diff line number Diff line change
Expand Up @@ -383,15 +383,6 @@ https://github.com/aantron/dream/issues
(* TODO If not removing this, move it to section Routing. *)
(**/**)

(**/**)
val version : request -> int * int
[@@ocaml.deprecated
"Protocol version access is being removed from the API. Comment at
https://github.com/aantron/dream/issues
"]
(** Protocol version. [(1, 1)] for HTTP/1.1 and [(2, 0)] for HTTP/2. *)
(**/**)

val set_client : request -> string -> unit
(** Replaces the client. See {!Dream.val-client}. *)

Expand Down Expand Up @@ -423,15 +414,6 @@ https://github.com/aantron/dream/issues
(** Replaces the path. See {!Dream.val-path}. *)
(**/**)

(**/**)
val with_version : int * int -> request -> request
[@@ocaml.deprecated
"Protocol version access is being removed from the API. Comment at
https://github.com/aantron/dream/issues
"]
(** Replaces the version. See {!Dream.version}. *)
(**/**)

val query : request -> string -> string option
(** First query parameter with the given name. See
{{:https://tools.ietf.org/html/rfc3986#section-3.4} RFC 3986 §3.4} and
Expand Down Expand Up @@ -2564,7 +2546,6 @@ https://aantron.github.io/dream/#val-set_field
val request :
?method_:[< method_ ] ->
?target:string ->
?version:int * int ->
?headers:(string * string) list ->
string -> request
(** [Dream.request body] creates a fresh request with the given body for
Expand Down
6 changes: 2 additions & 4 deletions src/http/error_handler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,9 @@ let dump (error : Catch.error) =
begin match error.request with
| None -> ()
| Some request ->
let major, minor = Message.version request in
p "\n\n%s %s HTTP/%i.%i"
p "\n\n%s %s"
(Method.method_to_string (Message.method_ request))
(Message.target request)
major minor;
(Message.target request);

Message.all_headers request
|> List.iter (fun (name, value) -> p "\n%s: %s" name value);
Expand Down
8 changes: 2 additions & 6 deletions src/http/http.ml
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ let wrap_handler
to_dream_method httpaf_request.meth in
let target =
httpaf_request.target in
let version =
(httpaf_request.version.major, httpaf_request.version.minor) in
let headers =
Httpaf.Headers.to_list httpaf_request.headers in

Expand All @@ -94,7 +92,7 @@ let wrap_handler
Stream.stream body Stream.no_writer in

let request : Message.request =
Helpers.request ~client ~method_ ~target ~tls ~version ~headers body in
Helpers.request ~client ~method_ ~target ~tls ~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 @@ -198,8 +196,6 @@ let wrap_handler_h2
to_dream_method httpaf_request.meth in
let target =
httpaf_request.target in
let version =
(2, 0) in
let headers =
H2.Headers.to_list httpaf_request.headers in

Expand All @@ -219,7 +215,7 @@ let wrap_handler_h2
Stream.stream body Stream.no_writer in

let request : Message.request =
Helpers.request ~client ~method_ ~target ~tls ~version ~headers body in
Helpers.request ~client ~method_ ~target ~tls ~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
14 changes: 0 additions & 14 deletions src/pure/message.ml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,7 @@ module Fields = Hmap.Make (struct type 'a t = 'a field_metadata end)
type client = {
mutable method_ : Method.method_;
mutable target : string;
mutable version : int * int;
}
(* TODO Get rid of the version field completely? At least don't expose it in
Dream. It is only used internally on the server side to add the right
Content-Length, etc., headers. But even that can be moved out of the
middleware and into transport so that the version field is not necessary for
some middleware to decide which headers to add. *)

type server = {
mutable status : Status.status;
Expand Down Expand Up @@ -66,7 +60,6 @@ type middleware = handler -> handler
let request
?method_
?(target = "/")
?(version = 1, 1)
?(headers = [])
client_stream
server_stream =
Expand All @@ -81,7 +74,6 @@ let request
specific = {
method_;
target;
version;
};
headers;
client_stream;
Expand All @@ -96,18 +88,12 @@ let method_ request =
let target request =
request.specific.target

let version request =
request.specific.version

let set_method_ request method_ =
request.specific.method_ <- (method_ :> Method.method_)

let set_target request target =
request.specific.target <- target

let set_version request version =
request.specific.version <- version



(* Responses *)
Expand Down
3 changes: 0 additions & 3 deletions src/pure/message.mli
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,15 @@ type middleware = handler -> handler
val request :
?method_:[< Method.method_ ] ->
?target:string ->
?version:int * int ->
?headers:(string * string) list ->
Stream.stream ->
Stream.stream ->
request

val method_ : request -> Method.method_
val target : request -> string
val version : request -> int * int
val set_method_ : request -> [< Method.method_ ] -> unit
val set_target : request -> string -> unit
val set_version : request -> int * int -> unit



Expand Down
10 changes: 4 additions & 6 deletions src/server/helpers.ml
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,15 @@ let set_tls request tls =



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

let request_with_body ?method_ ?target ?version ?headers body =
Message.request
?method_ ?target ?version ?headers Stream.null (Stream.string body)
let request_with_body ?method_ ?target ?headers body =
Message.request ?method_ ?target ?headers Stream.null (Stream.string body)



Expand Down

0 comments on commit 2162ec7

Please sign in to comment.