rack-devel archive mirror (unofficial) https://groups.google.com/group/rack-devel
 help / color / mirror / Atom feed
From: Eric Wong <normalperson@yhbt.net>
To: rack-devel@googlegroups.com
Subject: [PATCH] lint: avoid TypeError on non-Hash-like response headers
Date: Tue, 22 Jan 2013 11:37:49 +0000	[thread overview]
Message-ID: <20130122113749.GA31589@dcvr.yhbt.net> (raw)

According to SPEC (and check_headers), Response headers need only
respond to #each.  Thus, check_hijack_response should rely on
Rack::Utils::HeaderHash if it wishes to access the headers in a
hash-like fashion.
---
  The following changes since commit 0cba6a4d5aeb1ac8768b6ca36320731487fb596b:

    Update gemspec version, Rack 1.5.0 (2013-01-21 23:36:04 -0800)

  are available in the git repository at:

    git://bogomips.org/rack lint-headerhash

  for you to fetch changes up to b20b0023d6f4676a6f0645a522656b384446562a:

    lint: avoid TypeError on non-Hash-like response headers (2013-01-22 11:36:04 +0000)

  ----------------------------------------------------------------
  Eric Wong (1):
        lint: avoid TypeError on non-Hash-like response headers

   lib/rack/lint.rb  | 5 +++++
   test/spec_lint.rb | 7 +++++++
   2 files changed, 12 insertions(+)

diff --git a/lib/rack/lint.rb b/lib/rack/lint.rb
index 338f7f0..1bc2127 100644
--- a/lib/rack/lint.rb
+++ b/lib/rack/lint.rb
@@ -500,6 +500,11 @@ def check_hijack(env)
     ## It is also possible to hijack a response after the status and headers
     ## have been sent.
     def check_hijack_response(headers, env)
+
+      # this check uses headers like a hash, but the spec only requires
+      # headers respond to #each
+      headers = Rack::Utils::HeaderHash.new(headers)
+
       ## In order to do this, an application may set the special header
       ## <tt>rack.hijack</tt> to an object that responds to <tt>call</tt>
       ## accepting an argument that conforms to the <tt>rack.hijack_io</tt>
diff --git a/test/spec_lint.rb b/test/spec_lint.rb
index f824113..fb60b7e 100644
--- a/test/spec_lint.rb
+++ b/test/spec_lint.rb
@@ -231,6 +231,13 @@ def result.name
                        [200, {"Foo-Bar" => "one\ntwo\nthree", "Content-Length" => "0", "Content-Type" => "text/plain" }, []]
                      }).call(env({}))
     }.should.not.raise(Rack::Lint::LintError)
+
+    # non-Hash header responses should be allowed
+    lambda {
+      Rack::Lint.new(lambda { |env|
+                       [200, [%w(Content-Type text/plain), %w(Content-Length 0)], []]
+                     }).call(env({}))
+    }.should.not.raise(TypeError)
   end
 
   should "notice content-type errors" do
-- 
Eric Wong

             reply	other threads:[~2013-01-22 11:37 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-22 11:37 Eric Wong [this message]
2013-01-22 16:05 ` [PATCH] lint: avoid TypeError on non-Hash-like response headers James Tucker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://groups.google.com/group/rack-devel

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130122113749.GA31589@dcvr.yhbt.net \
    --to=rack-devel@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).