summary refs log tree commit
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-12-10 21:35:12 -0600
committerJoshua Peek <josh@joshpeek.com>2009-12-10 21:35:12 -0600
commit0f1bd2526b3972e131dccad32c7f7ea96a675880 (patch)
tree294aec828fc658d59fd7cd5ec9df8c09dda2805d
parent038ea40cbcc55f2cdb8fa31b19b4e224836534df (diff)
downloadrack-0f1bd2526b3972e131dccad32c7f7ea96a675880.tar.gz
HeaderHash#each yields Lint-OK multivalue headers
Rack::Lint does not allow header values yielded by #each to be
non-String objects, so we join them like we do in #to_hash.
This finally allows HeaderHash to be passed in the Rack response
as a header without needing #to_hash.

Signed-off-by: Joshua Peek <josh@joshpeek.com>
-rw-r--r--lib/rack/utils.rb6
-rw-r--r--test/spec_rack_utils.rb8
2 files changed, 14 insertions, 0 deletions
diff --git a/lib/rack/utils.rb b/lib/rack/utils.rb
index 4956177e..46362bab 100644
--- a/lib/rack/utils.rb
+++ b/lib/rack/utils.rb
@@ -273,6 +273,12 @@ module Rack
         hash.each { |k, v| self[k] = v }
       end
 
+      def each
+        super do |k, v|
+          yield(k, v.respond_to?(:to_ary) ? v.to_ary.join("\n") : v)
+        end
+      end
+
       def to_hash
         inject({}) do |hash, (k,v)|
           if v.respond_to? :to_ary
diff --git a/test/spec_rack_utils.rb b/test/spec_rack_utils.rb
index 755a1619..c61ab363 100644
--- a/test/spec_rack_utils.rb
+++ b/test/spec_rack_utils.rb
@@ -281,6 +281,14 @@ context "Rack::Utils::HeaderHash" do
     b.should.equal(a)
   end
 
+  specify "should convert Array values to Strings when responding to #each" do
+    h = Rack::Utils::HeaderHash.new("foo" => ["bar", "baz"])
+    h.each do |k,v|
+      k.should.equal("foo")
+      v.should.equal("bar\nbaz")
+    end
+  end
+
 end
 
 context "Rack::Utils::Context" do