Skip to content

Commit fa081fe

Browse files
committed
Add info response support
This patch adds support for 1XX informational responses. Those kinds of responses are sent along with normal responses, and flow looks like: > GET / HTTP/1.1 > Host: example.com > < HTTP/1.1 100 Continue < HTTP/1.1 200 OK < Content-Length: 12 < < Hello World! Notice that server responds (sends to the socket) 2 HTTP responses.
1 parent 1c25659 commit fa081fe

2 files changed

Lines changed: 34 additions & 1 deletion

File tree

lib/http/response/parser.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,11 @@ def read(size)
8686
end
8787

8888
def on_message_complete(_response)
89-
@finished[:message] = true
89+
if @state.http_status < 200
90+
reset
91+
else
92+
@finished[:message] = true
93+
end
9094
end
9195

9296
def reset

spec/lib/http/response/parser_spec.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,33 @@
4242
expect(subject.read(expected_body.size)).to eq(expected_body)
4343
end
4444
end
45+
46+
context "when got 100 Continue response" do
47+
let :raw_response do
48+
"HTTP/1.1 100 Continue\r\n\r\n" \
49+
"HTTP/1.1 200 OK\r\n" \
50+
"Content-Length: 12\r\n\r\n" \
51+
"Hello World!"
52+
end
53+
54+
context "when response is feeded in one part" do
55+
let(:parts) { [raw_response] }
56+
57+
it "skips to next non-info response" do
58+
expect(subject.status_code).to eq(200)
59+
expect(subject.headers).to eq("Content-Length" => "12")
60+
expect(subject.read(12)).to eq("Hello World!")
61+
end
62+
end
63+
64+
context "when response is feeded in many parts" do
65+
let(:parts) { raw_response.split(//) }
66+
67+
it "skips to next non-info response" do
68+
expect(subject.status_code).to eq(200)
69+
expect(subject.headers).to eq("Content-Length" => "12")
70+
expect(subject.read(12)).to eq("Hello World!")
71+
end
72+
end
73+
end
4574
end

0 commit comments

Comments
 (0)