lib/ftw/http/headers.rb in ftw-0.0.1 vs lib/ftw/http/headers.rb in ftw-0.0.4

- old
+ new

@@ -1,6 +1,6 @@ -require "net/ftw/namespace" +require "ftw/namespace" require "ftw/crlf" # HTTP Headers # # See RFC2616 section 4.2: <http://tools.ietf.org/html/rfc2616#section-4.2> @@ -28,10 +28,12 @@ # Any existing value(s) for this field are destroyed. def set(field, value) @headers[field.downcase] = value end # def set + alias_method :[]=, :set + # Set a header field to a specific value. # Any existing value(s) for this field are destroyed. def include?(field) @headers.include?(field.downcase) end # def include? @@ -97,10 +99,12 @@ def get(field) field = field.downcase return @headers[field] end # def get + alias_method :[], :get + # 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" @@ -114,9 +118,19 @@ end end end # end each public + def to_hash + return @headers + end # def to_hash + + public def to_s return @headers.collect { |name, value| "#{name}: #{value}" }.join(CRLF) + CRLF end # def to_s + + public + def inspect + return "#{self.class.name} <#{to_hash.inspect}>" + end # def inspect end # class FTW::HTTP::Headers