From mboxrd@z Thu Jan 1 00:00:00 1970 Delivered-To: chneukirchen@gmail.com Received: by 10.86.70.14 with SMTP id s14cs132959fga; Mon, 28 Sep 2009 03:14:41 -0700 (PDT) Received-SPF: pass (google.com: domain of grbounce-ceibQwUAAAB4YPBqaDIjI2bFOCxyyh3G=chneukirchen=gmail.com@googlegroups.com designates 10.140.133.21 as permitted sender) client-ip=10.140.133.21; Authentication-Results: mr.google.com; spf=pass (google.com: domain of grbounce-ceibQwUAAAB4YPBqaDIjI2bFOCxyyh3G=chneukirchen=gmail.com@googlegroups.com designates 10.140.133.21 as permitted sender) smtp.mail=grbounce-ceibQwUAAAB4YPBqaDIjI2bFOCxyyh3G=chneukirchen=gmail.com@googlegroups.com; dkim=pass header.i=grbounce-ceibQwUAAAB4YPBqaDIjI2bFOCxyyh3G=chneukirchen=gmail.com@googlegroups.com Received: from mr.google.com ([10.140.133.21]) by 10.140.133.21 with SMTP id g21mr719252rvd.16.1254132880597 (num_hops = 1); Mon, 28 Sep 2009 03:14:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=beta; h=domainkey-signature:received:received:x-sender:x-apparently-to :received:received:received:received-spf:received:date:from:to :subject:message-id:references:mime-version:content-type :content-disposition:in-reply-to:user-agent:reply-to:sender :precedence:x-google-loop:mailing-list:list-id:list-post:list-help :list-unsubscribe:x-beenthere-env:x-beenthere; bh=nILhDjHFci9UKfiFJcf5m7uKdjYhNlQWzgV21YNoiLA=; b=G3XYaHzc1Xh/QWwQNt6h6FEbzKQg+L4ay+1JgGo6ahbLldk4yBRbOShgHjBS7MAAYf Zu87sEzGdpFnq2vHavZQKTi6IKCOHcRjxjHvqtyysT9RRY6zsZBPT6ZAhkKyA43/vA7C ViEnwvUIIouRP+D3zSk7WgjJXXDrwB2N7oIsA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlegroups.com; s=beta; h=x-sender:x-apparently-to:received-spf:authentication-results:date :from:to:subject:message-id:references:mime-version:content-type :content-disposition:in-reply-to:user-agent:reply-to:sender :precedence:x-google-loop:mailing-list:list-id:list-post:list-help :list-unsubscribe:x-beenthere-env:x-beenthere; b=dAop3Z7zUmEcrPazKMDs0XSNTfy2LZZWZm684euhBytZ7uFm2IUVZ8KrRfn30TlNqx S5wNlqIrQH+pXfHBCBis6AiEcyLTQflFdw9rvQuWS8rYEKuq0S0XN7pflj6diQU1Afk3 22uIVR9hcG/gvsBXxY8h9E27tzIj20+oa/KwM= Received: by 10.140.133.21 with SMTP id g21mr98427rvd.16.1254132880549; Mon, 28 Sep 2009 03:14:40 -0700 (PDT) Received: by 10.106.99.27 with SMTP id w27gr1672prb.0; Mon, 28 Sep 2009 03:14:39 -0700 (PDT) X-Sender: normalperson@yhbt.net X-Apparently-To: rack-devel@googlegroups.com Received: by 10.115.86.40 with SMTP id o40mr313548wal.9.1254132878134; Mon, 28 Sep 2009 03:14:38 -0700 (PDT) Received: by 10.115.86.40 with SMTP id o40mr313547wal.9.1254132878112; Mon, 28 Sep 2009 03:14:38 -0700 (PDT) Return-Path: Received: from dcvr.yhbt.net (dcvr.yhbt.net [64.71.152.64]) by gmr-mx.google.com with ESMTP id 41si1732814pxi.8.2009.09.28.03.14.37; Mon, 28 Sep 2009 03:14:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of normalperson@yhbt.net designates 64.71.152.64 as permitted sender) client-ip=64.71.152.64; Authentication-Results: gmr-mx.google.com; spf=pass (google.com: best guess record for domain of normalperson@yhbt.net designates 64.71.152.64 as permitted sender) smtp.mail=normalperson@yhbt.net Received: from localhost (user-118bg0q.cable.mindspring.com [66.133.192.26]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPSA id 3E0261F7A1; Mon, 28 Sep 2009 10:14:37 +0000 (UTC) Date: Mon, 28 Sep 2009 03:14:36 -0700 From: Eric Wong To: rack-devel@googlegroups.com Subject: [PATCH 4/3] HeaderHash#each yields Lint-OK multivalue headers Message-ID: <20090928101436.GA24223@dcvr.yhbt.net> References: <1252100514-2748-1-git-send-email-normalperson@yhbt.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1252100514-2748-1-git-send-email-normalperson@yhbt.net> User-Agent: Mutt/1.5.18 (2008-05-17) Reply-To: rack-devel@googlegroups.com Sender: rack-devel@googlegroups.com Precedence: bulk X-Google-Loop: groups Mailing-List: list rack-devel@googlegroups.com; contact rack-devel+owner@googlegroups.com List-Id: List-Post: List-Help: List-Unsubscribe: , X-BeenThere-Env: rack-devel@googlegroups.com X-BeenThere: rack-devel@googlegroups.com 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. --- Oops! :x lib/rack/utils.rb | 6 ++++++ test/spec_rack_utils.rb | 8 ++++++++ 2 files changed, 14 insertions(+), 0 deletions(-) diff --git a/lib/rack/utils.rb b/lib/rack/utils.rb index 21b58c9..ba36742 100644 --- a/lib/rack/utils.rb +++ b/lib/rack/utils.rb @@ -268,6 +268,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 3586f8c..4a883ea 100644 --- a/test/spec_rack_utils.rb +++ b/test/spec_rack_utils.rb @@ -276,6 +276,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 -- Eric Wong