Class | FTW::HTTP::Headers |
In: |
lib/ftw/http/headers.rb
lib/ftw/http/headers.rb |
Parent: | Object |
See RFC2616 section 4.2: <tools.ietf.org/html/rfc2616#section-4.2>
Section 14.44 says Field Names in the header are case-insensitive, so this library always forces field names to be lowercase. This includes get() calls.
headers.set("HELLO", "world") headers.get("hello") # ===> "world"
Make a new headers container.
@param [Hash, optional] a hash of headers to start with.
Make a new headers container.
@param [Hash, optional] a hash of headers to start with.
Add a header field with a value.
If this field already exists, another value is added. If this field does not already exist, it is set.
Add a header field with a value.
If this field already exists, another value is added. If this field does not already exist, it is set.
Iterate over headers. Given to the block are two arguments, the field name and the field value. For fields with multiple values, you will receive that same field name multiple times, like:
yield "Host", "www.example.com" yield "X-Forwarded-For", "1.2.3.4" yield "X-Forwarded-For", "1.2.3.5"
Iterate over headers. Given to the block are two arguments, the field name and the field value. For fields with multiple values, you will receive that same field name multiple times, like:
yield "Host", "www.example.com" yield "X-Forwarded-For", "1.2.3.4" yield "X-Forwarded-For", "1.2.3.5"
Get a field value.
@return [String] if there is only one value for this field @return [Array] if there are multiple values for this field @return [nil] if there are no values for this field
Get a field value.
@return [String] if there is only one value for this field @return [Array] if there are multiple values for this field @return [nil] if there are no values for this field
Removes a header entry. If the header has multiple values (like X-Forwarded-For can), you can delete a specific entry by passing the value of the header field to remove.
# Remove all X-Forwarded-For entries headers.remove("X-Forwarded-For") # Remove a specific X-Forwarded-For entry headers.remove("X-Forwarded-For", "1.2.3.4")
Removes a header entry. If the header has multiple values (like X-Forwarded-For can), you can delete a specific entry by passing the value of the header field to remove.
# Remove all X-Forwarded-For entries headers.remove("X-Forwarded-For") # Remove a specific X-Forwarded-For entry headers.remove("X-Forwarded-For", "1.2.3.4")
Serialize this object to a string in HTTP format described by RFC2616
Example:
headers = FTW::HTTP::Headers.new headers.add("Host", "example.com") headers.add("X-Forwarded-For", "1.2.3.4") headers.add("X-Forwarded-For", "192.168.0.1") puts headers.to_s # Result Host: example.com X-Forwarded-For: 1.2.3.4 X-Forwarded-For: 192.168.0.1
Serialize this object to a string in HTTP format described by RFC2616
Example:
headers = FTW::HTTP::Headers.new headers.add("Host", "example.com") headers.add("X-Forwarded-For", "1.2.3.4") headers.add("X-Forwarded-For", "192.168.0.1") puts headers.to_s # Result Host: example.com X-Forwarded-For: 1.2.3.4 X-Forwarded-For: 192.168.0.1