From b20b0023d6f4676a6f0645a522656b384446562a Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 22 Jan 2013 11:29:59 +0000 Subject: lint: avoid TypeError on non-Hash-like response headers 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. --- 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 338f7f09..1bc2127f 100644 --- a/lib/rack/lint.rb +++ b/lib/rack/lint.rb @@ -500,6 +500,11 @@ module Rack ## 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 ## rack.hijack to an object that responds to call ## accepting an argument that conforms to the rack.hijack_io diff --git a/test/spec_lint.rb b/test/spec_lint.rb index f824113f..fb60b7ef 100644 --- a/test/spec_lint.rb +++ b/test/spec_lint.rb @@ -231,6 +231,13 @@ describe Rack::Lint do [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 -- cgit v1.2.3-24-ge0c7