From e4b9845a61cd5290d926d2a3252fa8fe0e01cf3f Mon Sep 17 00:00:00 2001 From: thomas morgan Date: Fri, 27 Oct 2023 11:26:01 -0600 Subject: [PATCH] ensure connections are marked not persistent when 1xx or body is Remainder --- lib/protocol/http1/connection.rb | 10 +++++++++- test/protocol/http1/connection.rb | 5 ++++- test/protocol/http1/hijack.rb | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/protocol/http1/connection.rb b/lib/protocol/http1/connection.rb index 43d1224..3388ca1 100644 --- a/lib/protocol/http1/connection.rb +++ b/lib/protocol/http1/connection.rb @@ -423,6 +423,7 @@ def read_fixed_body(length) end def read_remainder_body + @persistent = false Body::Remainder.new(@stream) end @@ -469,7 +470,14 @@ def read_response_body(method, status, headers) return nil end - if (status >= 100 and status < 200) or status == 204 or status == 304 + if status >= 100 and status < 200 + # At the moment this is returned, the Remainder represents any + # future response on the stream. The Remainder may be used directly + # or discarded, or read_response may be called again. + return read_remainder_body + end + + if status == 204 or status == 304 return nil end diff --git a/test/protocol/http1/connection.rb b/test/protocol/http1/connection.rb index 4da79bd..732143e 100644 --- a/test/protocol/http1/connection.rb +++ b/test/protocol/http1/connection.rb @@ -204,7 +204,9 @@ with '#read_response_body' do with "GET" do it "should ignore body for informational responses" do - expect(client.read_response_body("GET", 100, {'content-length' => '10'})).to be_nil + body = client.read_response_body("GET", 100, {'content-length' => '10'}) + expect(body).to be_a(::Protocol::HTTP1::Body::Remainder) + expect(client.persistent).to be == false end it "should ignore body for no content responses" do @@ -214,6 +216,7 @@ it "should handle non-chunked transfer-encoding" do body = client.read_response_body("GET", 200, {'transfer-encoding' => ['identity']}) expect(body).to be_a(::Protocol::HTTP1::Body::Remainder) + expect(client.persistent).to be == false end it "should be an error if both transfer-encoding and content-length is set" do diff --git a/test/protocol/http1/hijack.rb b/test/protocol/http1/hijack.rb index bfdfbf6..463c11c 100644 --- a/test/protocol/http1/hijack.rb +++ b/test/protocol/http1/hijack.rb @@ -44,7 +44,7 @@ expect(version).to be == response_version expect(status).to be == 101 expect(headers).to be == response_headers - expect(body).to be_nil # due to 101 status + expect(body).to be_a(::Protocol::HTTP1::Body::Remainder) # due to 101 status client_stream = client.hijack!