Skip to content

Commit 7d3a412

Browse files
samuel-williams-shopifyioquatix
authored andcommitted
Head.for(nil) -> nil.
1 parent fd9d606 commit 7d3a412

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

lib/protocol/http/body/head.rb

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,17 @@ module Body
1212
# Represents a body suitable for HEAD requests, in other words, a body that is empty and has a known length.
1313
class Head < Readable
1414
# Create a head body for the given body, capturing its length and then closing it.
15+
#
16+
# @parameter body [Readable | Nil] the body to create a head for.
17+
# @returns [Head | Nil] the head body, or nil if the body is nil.
1518
def self.for(body)
16-
head = self.new(body.length)
17-
18-
body.close
19+
if body
20+
head = self.new(body.length)
21+
body.close
22+
return head
23+
end
1924

20-
return head
25+
return nil
2126
end
2227

2328
# Initialize the head body with the given length.

test/protocol/http/body/head.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,11 @@
5656
body.close
5757
end
5858
end
59+
60+
with ".for with nil body" do
61+
it "returns nil when body is nil" do
62+
body = subject.for(nil)
63+
expect(body).to be_nil
64+
end
65+
end
5966
end

0 commit comments

Comments
 (0)