Skip to content

Commit 9cfcbd7

Browse files
authored
Ensure connections are marked not persistent when 1xx or body is Remainder. (#26)
1 parent 8fa447d commit 9cfcbd7

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

lib/protocol/http1/connection.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ def read_fixed_body(length)
423423
end
424424

425425
def read_remainder_body
426+
@persistent = false
426427
Body::Remainder.new(@stream)
427428
end
428429

@@ -469,7 +470,14 @@ def read_response_body(method, status, headers)
469470
return nil
470471
end
471472

472-
if (status >= 100 and status < 200) or status == 204 or status == 304
473+
if status >= 100 and status < 200
474+
# At the moment this is returned, the Remainder represents any
475+
# future response on the stream. The Remainder may be used directly
476+
# or discarded, or read_response may be called again.
477+
return read_remainder_body
478+
end
479+
480+
if status == 204 or status == 304
473481
return nil
474482
end
475483

test/protocol/http1/connection.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,9 @@
204204
with '#read_response_body' do
205205
with "GET" do
206206
it "should ignore body for informational responses" do
207-
expect(client.read_response_body("GET", 100, {'content-length' => '10'})).to be_nil
207+
body = client.read_response_body("GET", 100, {'content-length' => '10'})
208+
expect(body).to be_a(::Protocol::HTTP1::Body::Remainder)
209+
expect(client.persistent).to be == false
208210
end
209211

210212
it "should ignore body for no content responses" do
@@ -214,6 +216,7 @@
214216
it "should handle non-chunked transfer-encoding" do
215217
body = client.read_response_body("GET", 200, {'transfer-encoding' => ['identity']})
216218
expect(body).to be_a(::Protocol::HTTP1::Body::Remainder)
219+
expect(client.persistent).to be == false
217220
end
218221

219222
it "should be an error if both transfer-encoding and content-length is set" do

test/protocol/http1/hijack.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
expect(headers).to have_keys(
4646
'upgrade' => be == ['websocket'],
4747
)
48-
expect(body).to be_nil # due to 101 status
48+
expect(body).to be_a(::Protocol::HTTP1::Body::Remainder) # due to 101 status
4949

5050
client_stream = client.hijack!
5151

0 commit comments

Comments
 (0)