Skip to content

Commit

Permalink
Fix r663197
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66320 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
nobu authored and hsbt committed Feb 21, 2020
1 parent c56b774 commit 0310ba2
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions lib/net/http/header.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def initialize_http_header(initheader)
if value.count("\r\n") > 0
raise ArgumentError, "header #{key} has field value #{value.inspect}, this cannot include CR/LF"
end
@header[key.to_str.downcase] = [value]
@header[key.to_s.downcase] = [value]
end
end
end
Expand All @@ -36,14 +36,14 @@ def size #:nodoc: obsolete
# Returns the header field corresponding to the case-insensitive key.
# For example, a key of "Content-Type" might return "text/html"
def [](key)
a = @header[key.to_str.downcase] or return nil
a = @header[key.to_s.downcase] or return nil
a.join(', ')
end

# Sets the header field corresponding to the case-insensitive key.
def []=(key, val)
unless val
@header.delete key.to_str.downcase
@header.delete key.to_s.downcase
return val
end
set_field(key, val)
Expand All @@ -65,7 +65,7 @@ def []=(key, val)
# p request.get_fields('X-My-Header') #=> ["a", "b", "c"]
#
def add_field(key, val)
stringified_downcased_key = key.to_str.downcase
stringified_downcased_key = key.to_s.downcase
if @header.key?(stringified_downcased_key)
append_field_value(@header[stringified_downcased_key], val)
else
Expand All @@ -78,13 +78,13 @@ def add_field(key, val)
when Enumerable
ary = []
append_field_value(ary, val)
@header[key.to_str.downcase] = ary
@header[key.to_s.downcase] = ary
else
val = val.to_s # for compatibility use to_s instead of to_str
if val.b.count("\r\n") > 0
raise ArgumentError, 'header field value cannot include CR/LF'
end
@header[key.to_str.downcase] = [val]
@header[key.to_s.downcase] = [val]
end
end

Expand Down Expand Up @@ -113,7 +113,7 @@ def add_field(key, val)
# #=> "session=al98axx; expires=Fri, 31-Dec-1999 23:58:23, query=rubyscript; expires=Fri, 31-Dec-1999 23:58:23"
#
def get_fields(key)
stringified_downcased_key = key.to_str.downcase
stringified_downcased_key = key.to_s.downcase
return nil unless @header[stringified_downcased_key]
@header[stringified_downcased_key].dup
end
Expand All @@ -123,7 +123,7 @@ def get_fields(key)
# raises an IndexError if there's no header field named +key+
# See Hash#fetch
def fetch(key, *args, &block) #:yield: +key+
a = @header.fetch(key.to_str.downcase, *args, &block)
a = @header.fetch(key.to_s.downcase, *args, &block)
a.kind_of?(Array) ? a.join(', ') : a
end

Expand Down Expand Up @@ -184,12 +184,12 @@ def each_value #:yield: +value+

# Removes a header field, specified by case-insensitive key.
def delete(key)
@header.delete(key.to_str.downcase)
@header.delete(key.to_s.downcase)
end

# true if +key+ header exists.
def key?(key)
@header.key?(key.to_str.downcase)
@header.key?(key.to_s.downcase)
end

# Returns a Hash consisting of header names and array of values.
Expand Down

0 comments on commit 0310ba2

Please sign in to comment.