Skip to content

Commit

Permalink
Merge branch 'master' into http-upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
dhouse-js committed May 24, 2021
2 parents 60f137b + cc7478a commit 2a36491
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/client_connection.ml
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,16 @@ module Oneshot = struct
let next_write_operation t =
flush_request_body t;
if Body.is_closed t.request_body
(* Even though we've just done [flush_request_body], it might still be the case that
[Body.has_pending_output] returns true, because it does so when we've written all
output except for the final chunk. *)
&& not (Body.has_pending_output t.request_body)
then Writer.close t.writer;
Writer.next t.writer
;;

let yield_writer t k =
if Body.is_closed t.request_body
if Body.is_closed t.request_body && not (Body.has_pending_output t.request_body)
then begin
Writer.close t.writer;
k ()
Expand Down
23 changes: 22 additions & 1 deletion lib_test/test_client_connection.ml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,27 @@ let test_get () =
Body.close_writer body;
write_request t request';
read_response t response;
read_string t "d\r\nHello, world!\r\n0\r\n\r\n";
read_string t "d\r\nHello, world!\r\n0\r\n\r\n"
;;

let test_send_streaming_body () =
let request' = Request.create `GET "/" ~headers:Headers.encoding_chunked in
let response = Response.create `OK ~headers:Headers.encoding_chunked in
let body, t =
request
request'
~response_handler:(default_response_handler response)
~error_handler:no_error_handler
in
write_request t request';
read_response t response;
Body.write_string body "hello";
write_string t "5\r\nhello\r\n";
Body.write_string body "world";
Body.close_writer body;
write_string t "5\r\nworld\r\n";
write_string t "0\r\n\r\n";
writer_closed t
;;

let test_response_eof () =
Expand Down Expand Up @@ -259,6 +279,7 @@ let test_failed_response_parse () =

let tests =
[ "GET" , `Quick, test_get
; "send streaming body", `Quick, test_send_streaming_body
; "Response EOF", `Quick, test_response_eof
; "Response header order preserved", `Quick, test_response_header_order
; "report_exn" , `Quick, test_report_exn
Expand Down

0 comments on commit 2a36491

Please sign in to comment.