diff options
author | Eric Wong <normalperson@yhbt.net> | 2009-12-10 21:34:50 -0600 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2009-12-10 21:34:50 -0600 |
commit | 038ea40cbcc55f2cdb8fa31b19b4e224836534df (patch) | |
tree | 4bfd524ed4c191e599df6fa7055131099960e248 | |
parent | 8f836f406ca10274c6465e17c2b5646257a8412b (diff) | |
download | rack-038ea40cbcc55f2cdb8fa31b19b4e224836534df.tar.gz |
CommonLogger uses HeaderHash to lookup Content-Length
Since HeaderHash is cheaper to use now, encourage its usage instead of reinventing a way to lookup header values with an enforced O(n) overhead. Under best conditions, this can now be done in O(1) time if the rest of our middleware stack already uses (and passes) HeaderHash. This does make things slower if CommonLogger is the only middleware in the stack, however that's probably not too common. Signed-off-by: Joshua Peek <josh@joshpeek.com>
-rw-r--r-- | lib/rack/commonlogger.rb | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/lib/rack/commonlogger.rb b/lib/rack/commonlogger.rb index 880f0fbf..1edc9b83 100644 --- a/lib/rack/commonlogger.rb +++ b/lib/rack/commonlogger.rb @@ -16,6 +16,7 @@ module Rack def call(env) began_at = Time.now status, header, body = @app.call(env) + header = Utils::HeaderHash.new(header) log(env, status, header, began_at) [status, header, body] end @@ -41,12 +42,8 @@ module Rack end def extract_content_length(headers) - headers.each do |key, value| - if key.downcase == 'content-length' - return value.to_s == '0' ? '-' : value - end - end - '-' + value = headers['Content-Length'] or return '-' + value.to_s == '0' ? '-' : value end end end |