Skip to content

Commit

Permalink
Avoid creating an extra Hash object when no options were given
Browse files Browse the repository at this point in the history
  • Loading branch information
amatsuda committed Dec 22, 2022
1 parent 055f71c commit 15ab722
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions actionpack/lib/action_controller/metal/head.rb
Expand Up @@ -18,18 +18,20 @@ module Head
# render
#
# See Rack::Utils::SYMBOL_TO_STATUS_CODE for a full list of valid +status+ symbols.
def head(status, options = {})
def head(status, options = nil)
if status.is_a?(Hash)
raise ArgumentError, "#{status.inspect} is not a valid value for `status`."
end

status ||= :ok

location = options.delete(:location)
content_type = options.delete(:content_type)
if options
location = options.delete(:location)
content_type = options.delete(:content_type)

options.each do |key, value|
headers[key.to_s.split(/[-_]/).each { |v| v[0] = v[0].upcase }.join("-")] = value.to_s
options.each do |key, value|
headers[key.to_s.split(/[-_]/).each { |v| v[0] = v[0].upcase }.join("-")] = value.to_s
end
end

self.status = status
Expand Down

0 comments on commit 15ab722

Please sign in to comment.