Skip to content

Head.for(nil) -> nil. #83

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions lib/protocol/http/body/head.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,17 @@ module Body
# Represents a body suitable for HEAD requests, in other words, a body that is empty and has a known length.
class Head < Readable
# Create a head body for the given body, capturing its length and then closing it.
#
# @parameter body [Readable | Nil] the body to create a head for.
# @returns [Head | Nil] the head body, or nil if the body is nil.
def self.for(body)
head = self.new(body.length)

body.close
if body
head = self.new(body.length)
body.close
return head
end

return head
return nil
end

# Initialize the head body with the given length.
Expand Down
7 changes: 7 additions & 0 deletions test/protocol/http/body/head.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,11 @@
body.close
end
end

with ".for with nil body" do
it "returns nil when body is nil" do
body = subject.for(nil)
expect(body).to be_nil
end
end
end
Loading