Method: Gem::Net::HTTPHeader#add_field
- Defined in:
- lib/rubygems/net-http/lib/net/http/header.rb
#add_field(key, val) ⇒ Object
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:
req = Gem::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"]
261 262 263 264 265 266 267 268 |
# File 'lib/rubygems/net-http/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 |