rack-devel archive mirror (unofficial) https://groups.google.com/group/rack-devel
 help / color / mirror / code / Atom feed
* [PATCH] lint: avoid TypeError on non-Hash-like response headers
@ 2013-01-22 11:37 Eric Wong
  2013-01-22 16:05 ` James Tucker
  0 siblings, 1 reply; 2+ messages in thread
From: Eric Wong @ 2013-01-22 11:37 UTC (permalink / raw)
  To: rack-devel

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] lint: avoid TypeError on non-Hash-like response headers
  2013-01-22 11:37 [PATCH] lint: avoid TypeError on non-Hash-like response headers Eric Wong
@ 2013-01-22 16:05 ` James Tucker
  0 siblings, 0 replies; 2+ messages in thread
From: James Tucker @ 2013-01-22 16:05 UTC (permalink / raw)
  To: rack-devel

[-- Attachment #1: Type: text/plain, Size: 149 bytes --]

Diligent as always, thanks Eric!

On Jan 22, 2013, at 3:37 AM, Eric Wong <normalperson@yhbt.net> wrote:

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


[-- Attachment #2: Type: text/html, Size: 1769 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-01-22 16:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-22 11:37 [PATCH] lint: avoid TypeError on non-Hash-like response headers Eric Wong
2013-01-22 16:05 ` James Tucker

Code repositories for project(s) associated with this inbox:

	https://80x24.org/mirrors/rack.git

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).