From mboxrd@z Thu Jan 1 00:00:00 1970 Delivered-To: chneukirchen@gmail.com Received: by 10.86.23.1 with SMTP id 1cs150219fgw; Fri, 4 Sep 2009 14:42:06 -0700 (PDT) Received-SPF: pass (google.com: domain of grbounce-ceibQwUAAAB4YPBqaDIjI2bFOCxyyh3G=chneukirchen=gmail.com@googlegroups.com designates 10.143.26.38 as permitted sender) client-ip=10.143.26.38; Authentication-Results: mr.google.com; spf=pass (google.com: domain of grbounce-ceibQwUAAAB4YPBqaDIjI2bFOCxyyh3G=chneukirchen=gmail.com@googlegroups.com designates 10.143.26.38 as permitted sender) smtp.mail=grbounce-ceibQwUAAAB4YPBqaDIjI2bFOCxyyh3G=chneukirchen=gmail.com@googlegroups.com; dkim=pass header.i=grbounce-ceibQwUAAAB4YPBqaDIjI2bFOCxyyh3G=chneukirchen=gmail.com@googlegroups.com Received: from mr.google.com ([10.143.26.38]) by 10.143.26.38 with SMTP id d38mr275926wfj.6.1252100525275 (num_hops = 1); Fri, 04 Sep 2009 14:42:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=beta; h=domainkey-signature:received:received:x-sender:x-apparently-to :received:received:received:received-spf:received:from:to:cc:subject :date:message-id:x-mailer:in-reply-to:references:reply-to:sender :precedence:x-google-loop:mailing-list:list-id:list-post:list-help :list-unsubscribe:x-beenthere-env:x-beenthere; bh=dium3k1zRaR+jPpYfct7Fj2xXDA5QUZGMM3HJJ2aB8Q=; b=39pl4RkL40Cs+vHpK+YJfk2cinGjRVAcjtlWH40rOjXVlf2nhuz+wuSqGotRnhUsAp T4QUSk0pjO+SyJ64n24/bEj5O8xPAhCjVmN282414Vez7yx6FNhAMKWjn+zS8leD0xja PCVN5fzzzlgn6v/O9GdjseVFSuUX1cDGISOqo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlegroups.com; s=beta; h=x-sender:x-apparently-to:received-spf:authentication-results:from :to:cc:subject:date:message-id:x-mailer:in-reply-to:references :reply-to:sender:precedence:x-google-loop:mailing-list:list-id :list-post:list-help:list-unsubscribe:x-beenthere-env:x-beenthere; b=11umrgxfRJLcxZAiZySKhotIBIVmiJnYrDZTdsc3Jo9kNRuMZ33/8vD4y3kLkqd80I Whhga5aO9PyCDQjgvxmdZgckoFnjpBtZNGroTh5MC41XICX64A4cLQZI33qd1nwc/Ocw 5k+mbGycWfXJU0w+4GUN/E49wO8DvqBrQbn58= Received: by 10.143.26.38 with SMTP id d38mr41513wfj.6.1252100525227; Fri, 04 Sep 2009 14:42:05 -0700 (PDT) Received: by 10.107.171.33 with SMTP id y33gr1642pro.0; Fri, 04 Sep 2009 14:42:04 -0700 (PDT) X-Sender: normalperson@yhbt.net X-Apparently-To: rack-devel@googlegroups.com Received: by 10.143.27.39 with SMTP id e39mr1889637wfj.26.1252100522608; Fri, 04 Sep 2009 14:42:02 -0700 (PDT) Received: by 10.143.27.39 with SMTP id e39mr1889636wfj.26.1252100522589; Fri, 04 Sep 2009 14:42:02 -0700 (PDT) Return-Path: Received: from dcvr.yhbt.net (dcvr.yhbt.net [64.71.152.64]) by gmr-mx.google.com with ESMTP id 25si337559pzk.15.2009.09.04.14.42.02; Fri, 04 Sep 2009 14:42:02 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of normalperson@yhbt.net designates 64.71.152.64 as permitted sender) client-ip=64.71.152.64; Authentication-Results: gmr-mx.google.com; spf=pass (google.com: best guess record for domain of normalperson@yhbt.net designates 64.71.152.64 as permitted sender) smtp.mail=normalperson@yhbt.net Received: from localhost (unknown [12.186.229.34]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPSA id 064CF1F5D0; Fri, 4 Sep 2009 21:42:02 +0000 (UTC) From: Eric Wong To: rack-devel@googlegroups.com Cc: Eric Wong Subject: [PATCH 3/3] CommonLogger uses HeaderHash to lookup Content-Length Date: Fri, 4 Sep 2009 14:41:54 -0700 Message-Id: <1252100514-2748-4-git-send-email-normalperson@yhbt.net> X-Mailer: git-send-email 1.6.4.2.236.gf324c In-Reply-To: <1252100514-2748-1-git-send-email-normalperson@yhbt.net> References: <1252100514-2748-1-git-send-email-normalperson@yhbt.net> Reply-To: rack-devel@googlegroups.com Sender: rack-devel@googlegroups.com Precedence: bulk X-Google-Loop: groups Mailing-List: list rack-devel@googlegroups.com; contact rack-devel+owner@googlegroups.com List-Id: List-Post: List-Help: List-Unsubscribe: , X-BeenThere-Env: rack-devel@googlegroups.com X-BeenThere: rack-devel@googlegroups.com 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. --- 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 880f0fb..1edc9b8 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 -- 1.6.4.2.236.gf324c