From 09cae70d5509530ed3abff9046b1dc0fe448b3b3 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 4 Sep 2009 19:19:28 -0700 Subject: use Rack::Utils::HeaderHash for $sent_http_* lookups No point in having extra code to do case-insensitive lookups, especially since the HeaderHash implementation is already in wide use and will only get faster as time goes by. --- lib/clogger/pure.rb | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) (limited to 'lib') diff --git a/lib/clogger/pure.rb b/lib/clogger/pure.rb index 108d036..718db9a 100644 --- a/lib/clogger/pure.rb +++ b/lib/clogger/pure.rb @@ -1,6 +1,8 @@ # -*- encoding: binary -*- # :stopdoc: -# + +require 'rack' + # Not at all optimized for performance, this was written based on # the original C extension code so it's not very Ruby-ish... class Clogger @@ -23,6 +25,7 @@ class Clogger raise TypeError, "app response not a 3 element Array: #{resp.inspect}" end status, headers, body = resp + headers = Rack::Utils::HeaderHash.new(headers) if wrap_body? @reentrant = env['rack.multithread'] @env, @status, @headers, @body = env, status, headers, body @@ -114,7 +117,7 @@ private case op[0] when OP_LITERAL; op[1] when OP_REQUEST; byte_xs(env[op[1]] || "-") - when OP_RESPONSE; byte_xs(get_sent_header(headers, op[1])) + when OP_RESPONSE; byte_xs(headers[op[1]] || "-") when OP_SPECIAL; special_var(op[1], env, status, headers) when OP_EVAL; eval(op[1]).to_s rescue "-" when OP_TIME_LOCAL; Time.now.strftime(op[1]) @@ -133,14 +136,4 @@ private }.join('') end - def get_sent_header(headers, match) - headers.each do |pair| - Array === pair && pair.size >= 2 or - raise TypeError, "headers not returning pairs" - key, value = pair - match == key.downcase and return value - end - "-" - end - end -- cgit v1.2.3-24-ge0c7