Skip to content

Commit

Permalink
Do not raise Error upon invalid content-length
Browse files Browse the repository at this point in the history
  • Loading branch information
ixti committed Aug 3, 2016
1 parent fc5022f commit a5e14fa
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
3 changes: 1 addition & 2 deletions lib/http/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,12 @@ def flush

# Value of the Content-Length header
#
# @raise [HTTP::Error] if presented Content-Type value is not integer
# @return [Integer, nil]
def content_length
value = @headers[Headers::CONTENT_LENGTH]
Integer(value) if value
rescue ArgumentError
raise Error, "Invalid value of Content-Type: #{value.inspect}"
nil
end

# Parsed Content-Type header
Expand Down
7 changes: 2 additions & 5 deletions spec/lib/http/response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,9 @@
it { is_expected.to eq 5 }
end

context "with Content-Length not an integer" do
context "with invalid Content-Length" do
let(:headers) { {"Content-Length" => "foo"} }

it "raises an error" do
expect { subject }.to raise_error(HTTP::Error)
end
it { is_expected.to be_nil }
end
end

Expand Down

0 comments on commit a5e14fa

Please sign in to comment.