Permalink
Browse files

Ensure Rack::ShowStatus passes on headers

darcs-hash:20070403200939-5d7f7-ef5ce0f8827f62c56b40260c75ca379a4d381b79.gz
  • Loading branch information...
1 parent 234c062 commit 6e640a692fb7fec7b1c1a12ac4cc76e8e4172d9a @tim tim committed Apr 3, 2007
Showing with 14 additions and 11 deletions.
  1. +5 −11 lib/rack/showstatus.rb
  2. +9 −0 test/spec_rack_showstatus.rb
View
@@ -20,17 +20,11 @@ def call(env)
status, headers, body = @app.call(env)
# client or server error, or explicit message
- if status.to_i >= 400 || env["rack.showstatus.detail"]
- empty = true
- body.each { empty = false; break }
- if empty || env["rack.showstatus.detail"]
- req = Rack::Request.new(env)
- message = Rack::Utils::HTTP_STATUS_CODES[status.to_i] || status.to_s
- detail = env["rack.showstatus.detail"] || message
- [status, {"Content-Type" => "text/html"}, [@template.result(binding)]]
- else
- [status, headers, body]
- end
+ if status.to_i >= 400 && body.empty? || env["rack.showstatus.detail"]
+ req = Rack::Request.new(env)
+ message = Rack::Utils::HTTP_STATUS_CODES[status.to_i] || status.to_s
+ detail = env["rack.showstatus.detail"] || message
+ [status, headers.merge("Content-Type" => "text/html"), [@template.result(binding)]]
else
[status, headers, body]
end
@@ -44,6 +44,15 @@
res.body.should == "foo!"
end
+ specify "should pass on original headers" do
+ headers = {"WWW-Authenticate" => "Basic blah"}
+
+ req = Rack::MockRequest.new(Rack::ShowStatus.new(lambda { |env| [401, headers, []] }))
+ res = req.get("/", :lint => true)
+
+ res["WWW-Authenticate"].should.equal("Basic blah")
+ end
+
specify "should replace existing messages if there is detail" do
req = Rack::MockRequest.new(Rack::ShowStatus.new(lambda { |env|
env["rack.showstatus.detail"] = "gone too meta."

0 comments on commit 6e640a6

Please sign in to comment.