lib/httpx/headers.rb in httpx-0.3.1 vs lib/httpx/headers.rb in httpx-0.4.0
- old
+ new
@@ -5,17 +5,19 @@
EMPTY = [].freeze # :nodoc:
class << self
def new(headers = nil)
return headers if headers.is_a?(self)
+
super
end
end
def initialize(headers = nil)
@headers = {}
return unless headers
+
headers.each do |field, value|
array_value(value).each do |v|
add(downcased(field), v)
end
end
@@ -42,11 +44,10 @@
# merges headers with another header-quack.
# the merge rule is, if the header already exists,
# ignore what the +other+ headers has. Otherwise, set
#
def merge(other)
- # TODO: deep-copy
headers = dup
other.each do |field, value|
headers[field] = value
end
headers
@@ -62,10 +63,11 @@
# sets +value+ (if not nil) as single value for the +field+ header.
#
def []=(field, value)
return unless value
+
@headers[downcased(field)] = array_value(value)
end
# deletes all values associated with +field+ header.
#
@@ -92,9 +94,10 @@
# returns the enumerable headers store in pairs of header field + the values in
# the comma-separated string format
#
def each
return enum_for(__method__) { @headers.size } unless block_given?
+
@headers.each do |field, value|
yield(field, value.join(", ")) unless value.empty?
end
end