Skip to content

Commit a5e14fa

Browse files
committed
Do not raise Error upon invalid content-length
See: #365 (comment)
1 parent fc5022f commit a5e14fa

File tree

2 files changed

+3
-7
lines changed

2 files changed

+3
-7
lines changed

lib/http/response.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,12 @@ def flush
8888

8989
# Value of the Content-Length header
9090
#
91-
# @raise [HTTP::Error] if presented Content-Type value is not integer
9291
# @return [Integer, nil]
9392
def content_length
9493
value = @headers[Headers::CONTENT_LENGTH]
9594
Integer(value) if value
9695
rescue ArgumentError
97-
raise Error, "Invalid value of Content-Type: #{value.inspect}"
96+
nil
9897
end
9998

10099
# Parsed Content-Type header

spec/lib/http/response_spec.rb

+2-5
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,9 @@
4040
it { is_expected.to eq 5 }
4141
end
4242

43-
context "with Content-Length not an integer" do
43+
context "with invalid Content-Length" do
4444
let(:headers) { {"Content-Length" => "foo"} }
45-
46-
it "raises an error" do
47-
expect { subject }.to raise_error(HTTP::Error)
48-
end
45+
it { is_expected.to be_nil }
4946
end
5047
end
5148

0 commit comments

Comments
 (0)