From 71c9f68603326a1c0d07a40da3d04875e66fafb9 Mon Sep 17 00:00:00 2001 From: Christian Schmidt Date: Sun, 26 Mar 2023 21:48:06 +0200 Subject: [PATCH 1/3] Add Connection#finished? --- lib/http/connection.rb | 4 ++++ spec/lib/http/connection_spec.rb | 2 ++ 2 files changed, 6 insertions(+) diff --git a/lib/http/connection.rb b/lib/http/connection.rb index 95a660cb..ba423ac9 100644 --- a/lib/http/connection.rb +++ b/lib/http/connection.rb @@ -132,6 +132,10 @@ def close @pending_request = false end + def finished? + !@pending_request && !@pending_response + end + # Whether we're keeping the conn alive # @return [Boolean] def keep_alive? diff --git a/spec/lib/http/connection_spec.rb b/spec/lib/http/connection_spec.rb index d7c9c546..1c25792b 100644 --- a/spec/lib/http/connection_spec.rb +++ b/spec/lib/http/connection_spec.rb @@ -58,9 +58,11 @@ connection.read_headers! buffer = String.new while (s = connection.readpartial(3)) + expect(connection.finished?).to be false if s != "" buffer << s end expect(buffer).to eq "1234567890" + expect(connection.finished?).to be true end end end From 98b530dc82f28eadabe01851401acf7d1f3b463a Mon Sep 17 00:00:00 2001 From: Christian Schmidt Date: Wed, 29 Mar 2023 19:14:19 +0200 Subject: [PATCH 2/3] Rename to finished_request? Co-authored-by: Tony Arcieri --- lib/http/connection.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/http/connection.rb b/lib/http/connection.rb index ba423ac9..2f7caef3 100644 --- a/lib/http/connection.rb +++ b/lib/http/connection.rb @@ -132,7 +132,7 @@ def close @pending_request = false end - def finished? + def finished_request? !@pending_request && !@pending_response end From 83bd0cd087b0cc73edd770d5c7f11243cd2088c9 Mon Sep 17 00:00:00 2001 From: Christian Schmidt Date: Wed, 29 Mar 2023 19:38:01 +0200 Subject: [PATCH 3/3] Update test --- spec/lib/http/connection_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/lib/http/connection_spec.rb b/spec/lib/http/connection_spec.rb index 1c25792b..2ce54e3b 100644 --- a/spec/lib/http/connection_spec.rb +++ b/spec/lib/http/connection_spec.rb @@ -58,11 +58,11 @@ connection.read_headers! buffer = String.new while (s = connection.readpartial(3)) - expect(connection.finished?).to be false if s != "" + expect(connection.finished_request?).to be false if s != "" buffer << s end expect(buffer).to eq "1234567890" - expect(connection.finished?).to be true + expect(connection.finished_request?).to be true end end end