lib/protocol/http/headers.rb in protocol-http-0.16.3 vs lib/protocol/http/headers.rb in protocol-http-0.17.0

- old
+ new

@@ -51,26 +51,24 @@ @fields = fields @indexed = indexed # Marks where trailers start in the @fields array. @tail = nil - @deferred = [] end def initialize_dup(other) super @fields = @fields.dup @indexed = @indexed.dup - @deferred = @deferred.dup + @tail = nil end def clear @fields.clear @indexed = nil @tail = nil - @deferred.clear end # An array of `[key, value]` pairs. attr :fields @@ -82,48 +80,29 @@ # @return the trailers if there are any. def trailers? @tail != nil end - def flatten! - unless @deferred.empty? - @tail ||= @fields.size - - @deferred.each do |key, value| - self.add(key, value.call) - end - end - end - # Enumerate all trailers, including evaluating all deferred headers. def trailers(&block) return nil unless self.include?(TRAILERS) + trailers! + return to_enum(:trailers) unless block_given? - flatten! - if @tail @fields.drop(@tail).each(&block) end end def freeze return if frozen? - # Ensure all deferred headers are evaluated: - self.flatten! - # Ensure @indexed is generated: self.to_h - # Remove all trailers: - self.delete(TRAILERS) - - # No longer has stateful trailers: - @tail = nil - @fields.freeze @indexed.freeze super end @@ -159,17 +138,11 @@ end # Add the specified header key value pair. # @param key [String] the header key. # @param value [String] the header value to assign. - # @yield dynamically generate the value when used as a trailer. - def add(key, value = nil, &block) - if block_given? - @deferred << [key, block] - self[TRAILERS] = key - else - self[key] = value - end + def add(key, value) + self[key] = value end # Set the specified header key to the specified value, replacing any existing header keys with the same name. # @param key [String] the header key to replace. # @param value [String] the header value to assign.