forked from httprb/http
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix parser so it properly parses headers
..when they are returned in parts Resolves: httprb#589
- Loading branch information
Piotr Boniecki
committed
Jan 22, 2020
1 parent
edfa4f1
commit e623d67
Showing
2 changed files
with
65 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe HTTP::Response::Parser do | ||
subject(:parser) { described_class.new } | ||
let(:raw_response) do | ||
"HTTP/1.1 200 OK\r\nContent-Length: 2\r\nContent-Type: application/json\r\nMyHeader: val\r\nEmptyHeader: \r\n\r\n{}" | ||
end | ||
let(:expected_headers) do | ||
{ | ||
"Content-Length" => "2", | ||
"Content-Type" => "application/json", | ||
"MyHeader" => "val", | ||
"EmptyHeader" => "" | ||
} | ||
end | ||
let(:expected_body) { "{}" } | ||
|
||
before do | ||
parts.each { |part| subject.add(part) } | ||
end | ||
|
||
context "whole response in one part" do | ||
let(:parts) { [raw_response] } | ||
|
||
it "parses headers" do | ||
expect(subject.headers.to_h).to eq(expected_headers) | ||
end | ||
|
||
it "parses body" do | ||
expect(subject.read(expected_body.size)).to eq(expected_body) | ||
end | ||
end | ||
|
||
context "response in many parts" do | ||
let(:parts) { raw_response.split(//) } | ||
|
||
it "parses headers" do | ||
expect(subject.headers.to_h).to eq(expected_headers) | ||
end | ||
|
||
it "parses body" do | ||
expect(subject.read(expected_body.size)).to eq(expected_body) | ||
end | ||
end | ||
end |