Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions cohttp-async/src/client.ml
Original file line number Diff line number Diff line change
Expand Up @@ -128,20 +128,19 @@ let callv ?interrupt ?ssl_config uri reqs =
let call ?interrupt ?ssl_config ?headers ?(chunked=false) ?(body=`Empty) meth uri =
(* Create a request, then make the request. Figure out an appropriate
transfer encoding *)
let req =
Copy link
Copy Markdown
Collaborator

@mseri mseri Aug 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is easier to read if you don't pipe such a large block. I'd suggest

let (req, body') = match chunked with
[...]
in
req >>= request ?interrupt ?ssl_config ~body:body' ~uri

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had another look at the code, similar blocks appear in other places. I am going to merge as is

begin
match chunked with
| false ->
Body_raw.disable_chunked_encoding body >>| fun (_body, body_length) ->
Request.make_for_client ?headers ~chunked ~body_length meth uri
Body_raw.disable_chunked_encoding body >>| fun (body, body_length) ->
Request.make_for_client ?headers ~chunked ~body_length meth uri, body
| true -> begin
Body.is_empty body >>| function
| true -> (* Don't used chunked encoding with an empty body *)
Request.make_for_client ?headers ~chunked:false ~body_length:0L meth uri
Request.make_for_client ?headers ~chunked:false ~body_length:0L meth uri, body
| false -> (* Use chunked encoding if there is a body *)
Request.make_for_client ?headers ~chunked:true meth uri
Request.make_for_client ?headers ~chunked:true meth uri, body
end
in
req >>= request ?interrupt ?ssl_config ~body ~uri
end >>= fun (req, body) -> request ?interrupt ?ssl_config ~body ~uri req

let get ?interrupt ?ssl_config ?headers uri =
call ?interrupt ?ssl_config ?headers ~chunked:false `GET uri
Expand Down