Skip to content

Commit

Permalink
http: simplify make
Browse files Browse the repository at this point in the history
  • Loading branch information
bikallem committed Jun 8, 2022
1 parent 6f723f4 commit 9609177
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 20 deletions.
1 change: 1 addition & 0 deletions http/src/dune
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
(library
(name http)
(libraries uri)
(public_name http))
23 changes: 10 additions & 13 deletions http/src/http.ml
Original file line number Diff line number Diff line change
Expand Up @@ -757,13 +757,15 @@ module Request = struct
Transfer.has_body req.encoding

let[@warning "-3"] make ?(meth = `GET) ?(version = `HTTP_1_1)
?(encoding = Transfer.Chunked) ?(headers = Header.empty) resource =
let encoding =
match Header.get_transfer_encoding headers with
| Transfer.(Chunked | Fixed _) as enc -> enc
| Unknown -> encoding
in
{ headers; meth; scheme = None; resource; version; encoding }
?(headers = Header.empty) resource =
{
headers;
meth;
scheme = Uri.scheme resource;
resource = Uri.path_and_query resource;
version;
encoding = Transfer.Unknown;
}
end

module Response = struct
Expand All @@ -790,12 +792,7 @@ module Response = struct
| i -> i

let make ?(version = `HTTP_1_1) ?(status = `OK) ?(flush = false)
?(encoding = Transfer.Chunked) ?(headers = Header.empty) () =
let encoding =
match Header.get_transfer_encoding headers with
| Transfer.(Chunked | Fixed _) as enc -> enc
| Unknown -> encoding
in
?(encoding = Transfer.Unknown) ?(headers = Header.empty) () =
{ encoding; headers; version; flush; status }

let headers t = t.headers
Expand Down
8 changes: 1 addition & 7 deletions http/src/http.mli
Original file line number Diff line number Diff line change
Expand Up @@ -385,18 +385,12 @@ module Request : sig
(** Return true whether the connection should be reused *)

val make :
?meth:Method.t ->
?version:Version.t ->
?encoding:Transfer.encoding ->
?headers:Header.t ->
string ->
t
?meth:Method.t -> ?version:Version.t -> ?headers:Header.t -> Uri.t -> t
(** [make res)] is [t] where [resource t] is [res]. The default values if not
specified are as follows:
- [meth] is [`GET]
- [version] is [`HTTP_1_1]
- [encoding] is [Transfer.Chunked]
- [headers] is [Header.empty] *)
end

Expand Down

0 comments on commit 9609177

Please sign in to comment.