Skip to content

Commit

Permalink
ensure connections are marked not persistent when 1xx or body is Rema…
Browse files Browse the repository at this point in the history
…inder
  • Loading branch information
zarqman authored and ioquatix committed Aug 28, 2024
1 parent da9095e commit 6221879
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
10 changes: 9 additions & 1 deletion lib/protocol/http1/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ def read_fixed_body(length)
end

def read_remainder_body
@persistent = false
Body::Remainder.new(@stream)
end

Expand Down Expand Up @@ -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

Expand Down
5 changes: 4 additions & 1 deletion test/protocol/http1/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,15 @@
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 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
Expand Down
2 changes: 1 addition & 1 deletion test/protocol/http1/hijack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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!

Expand Down

0 comments on commit 6221879

Please sign in to comment.