Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →
instance method
Net::HTTPHeader#add_field
add_field(key, val)
lib/net/http/header.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.3.0/lib/net/http/header.rb, line 261
def add_field(key, val)
stringified_downcased_key = key.downcase.to_s
if @header.key?(stringified_downcased_key)
append_field_value(@header[stringified_downcased_key], val)
else
set_field(key, val)
end
end
Adds value val to the value array for field key if the field exists; creates the field with the given key and val if it does not exist. see Fields:
Example
req = Net::HTTP::Get.new(uri) req.add_field('Foo', 'bar') req['Foo'] # => "bar" req.add_field('Foo', 'baz') req['Foo'] # => "bar, baz" req.add_field('Foo', %w[baz bam]) req['Foo'] # => "bar, baz, baz, bam" req.get_fields('Foo') # => ["bar", "baz", "baz", "bam"]