Skip to content

Commit

Permalink
Add info response support
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ixti committed Feb 7, 2020
1 parent 1c25659 commit 46a52dc
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/http/response/parser.rb
Expand Up @@ -86,7 +86,11 @@ def read(size)
end

def on_message_complete(_response)
@finished[:message] = true
if @state.http_status < 200
reset
else
@finished[:message] = true
end
end

def reset
Expand Down
29 changes: 29 additions & 0 deletions spec/lib/http/response/parser_spec.rb
Expand Up @@ -42,4 +42,33 @@
expect(subject.read(expected_body.size)).to eq(expected_body)
end
end

context "when got 100 Continue response" do
let :raw_response do
"HTTP/1.1 100 Continue\r\n\r\n" \
"HTTP/1.1 200 OK\r\n" \
"Content-Length: 12\r\n\r\n" \
"Hello World!"
end

context "when response is feeded in one part" do
let(:parts) { [raw_response] }

it "skips to next non-info response" do
expect(subject.status_code).to eq(200)
expect(subject.headers).to eq("Content-Length" => "12")
expect(subject.read(12)).to eq("Hello World!")
end
end

context "when response is feeded in many parts" do
let(:parts) { raw_response.split(//) }

it "skips to next non-info response" do
expect(subject.status_code).to eq(200)
expect(subject.headers).to eq("Content-Length" => "12")
expect(subject.read(12)).to eq("Hello World!")
end
end
end
end

0 comments on commit 46a52dc

Please sign in to comment.