Skip to content

Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

Net::HTTPHeader#add_field

(::interned key, untyped val) -> void
add_field(key, val)

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"]
See also #[]= #append_field_value #[] #basic_auth also in 4.1 · 4.0 · 3.3 · 3.2 · 3.1 · 3.0