Commit fb1e90c 1 parent 7a78d93 commit fb1e90c Copy full SHA for fb1e90c
File tree 2 files changed +28
-0
lines changed
2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -86,6 +86,13 @@ def flush
86
86
self
87
87
end
88
88
89
+ # Value of the Content-Length header
90
+ #
91
+ # @return [Integer]
92
+ def content_length
93
+ Integer ( headers [ Headers ::CONTENT_LENGTH ] ) if headers [ Headers ::CONTENT_LENGTH ]
94
+ end
95
+
89
96
# Parsed Content-Type header
90
97
#
91
98
# @return [HTTP::ContentType]
Original file line number Diff line number Diff line change 28
28
end
29
29
end
30
30
31
+ describe "#content_length" do
32
+ subject { response . content_length }
33
+
34
+ context "without Content-Length header" do
35
+ it { is_expected . to be_nil }
36
+ end
37
+
38
+ context "with Content-Length: 5" do
39
+ let ( :headers ) { { "Content-Length" => "5" } }
40
+ it { is_expected . to eq 5 }
41
+ end
42
+
43
+ context "with Content-Length not an integer" do
44
+ let ( :headers ) { { "Content-Length" => "foo" } }
45
+
46
+ it "raises an error" do
47
+ expect { subject } . to raise_error ( ArgumentError )
48
+ end
49
+ end
50
+ end
51
+
31
52
describe "mime_type" do
32
53
subject { response . mime_type }
33
54
You can’t perform that action at this time.
0 commit comments