Permalink
Browse files

Merge branch 'perfix' of http://github.com/thedarkone/rack into theda…

…rkone-perfix

* 'perfix' of http://github.com/thedarkone/rack:
  No need to delete a key that doesn't exist.
  Avoiding invoking #delete unless unnecessary.
  Fix the phantom header key bug.
  Revert "Don't set header to nil on HeaderHash#include?"
  • Loading branch information...
2 parents e9d7699 + be5a8b5 commit 511ee6fac9132cefe692834d3cd59c9e33e77640 @raggi raggi committed Oct 3, 2010
Showing with 10 additions and 4 deletions.
  1. +4 −4 lib/rack/utils.rb
  2. +6 −0 test/spec_utils.rb
View
@@ -314,13 +314,13 @@ def to_hash
end
def [](k)
- super(@names[k]) if @names[k]
- super(@names[k.downcase])
+ super(k) || super(@names[k.downcase])
end
def []=(k, v)
- delete k
- @names[k] = @names[k.downcase] = k
+ canonical = k.downcase
+ delete k if @names[canonical] && @names[canonical] != k # .delete is expensive, don't invoke it unless necessary
+ @names[k] = @names[canonical] = k
super k, v
end
View
@@ -309,6 +309,12 @@
end
end
+ should "not create headers out of thin air" do
+ h = Rack::Utils::HeaderHash.new
+ h['foo']
+ h['foo'].should.be.nil
+ h.should.not.include 'foo'
+ end
end
describe Rack::Utils::Context do

0 comments on commit 511ee6f

Please sign in to comment.