Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cohttp_async.Body.is_empty should return true iff pipe is empty #712

Merged
merged 1 commit into from
Sep 9, 2020
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions cohttp-async/src/body_raw.ml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ let is_empty (body:t) =
| `Pipe s ->
Pipe.values_available s
>>| function
|`Eof -> false
|`Eof -> true
|`Ok ->
match Pipe.peek s with
| Some "" -> true
| Some _ | None -> false
| None -> true
| Some _ -> false

let to_pipe = function
| `Empty -> Pipe.of_list []
Expand Down
15 changes: 14 additions & 1 deletion cohttp-async/test/test_async_integration.ml
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,27 @@ let ts =
assert_equal ~printer "expert 1" body;
Client.get ~headers uri >>= fun (_rsp, body) ->
Body.to_string body >>| fun body ->
assert_equal ~printer "expert 2" body
assert_equal ~printer "expert 2" body in
let check_body_empty_status () =
let is_empty = Cohttp_async.Body.is_empty in
let tests = [
Pipe.of_list [], true
; Pipe.of_list ["foo"; "bar"], false
; Pipe.of_list [""; "baz"], false]
in
Deferred.List.iter tests ~f:(fun (pipe, expected) ->
is_empty (`Pipe pipe)
>>| fun real ->
assert_equal expected real;
)
in
[ "empty chunk test", empty_chunk
; "large response", large_response
; "large request", large_request
; "pipelined chunk test", pipelined_chunk
; "large chunked response", large_chunked_response
; "expert response", expert_pipelined
; "check body is_empty status for pipes", check_body_empty_status
]
end

Expand Down