From c03045ecde0f3270d7458ba7ac0d76a25afc6fb2 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 29 Aug 2009 13:35:22 -0700 Subject: support "$request_uri" as a log variable This was documented in the README but never implemented. Some popular web servers set REQUEST_URI even though it's not required by Rack, so allow this variable to be used if possible. As a side effect, it is also less likely to be modified by certain handlers (*cough*Rails::Rack::Static*cough*). --- lib/clogger.rb | 1 + lib/clogger/pure.rb | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/clogger.rb b/lib/clogger.rb index 0e4148e..8e881c2 100644 --- a/lib/clogger.rb +++ b/lib/clogger.rb @@ -29,6 +29,7 @@ class Clogger :response_length => 4, # like body_bytes_sent, except "-" instead of "0" :ip => 5, # HTTP_X_FORWARDED_FOR || REMOTE_ADDR || - :pid => 6, # getpid() + :request_uri => 7 } private diff --git a/lib/clogger/pure.rb b/lib/clogger/pure.rb index 11c03f4..85c6777 100644 --- a/lib/clogger/pure.rb +++ b/lib/clogger/pure.rb @@ -63,6 +63,13 @@ private SPECIAL_RMAP = SPECIAL_VARS.inject([]) { |ary, (k,v)| ary[v] = k; ary } + def request_uri(env) + ru = env['REQUEST_URI'] and return byte_xs(ru) + qs = env['QUERY_STRING'] + qs.empty? or qs = "?#{byte_xs(qs)}" + "#{byte_xs(env['PATH_INFO'])}#{qs}" + end + def special_var(special_nr, env, status, headers) case SPECIAL_RMAP[special_nr] when :body_bytes_sent @@ -74,8 +81,10 @@ private qs = env['QUERY_STRING'] qs.empty? or qs = "?#{byte_xs(qs)}" "#{env['REQUEST_METHOD']} " \ - "#{byte_xs(env['PATH_INFO'])}#{qs} " \ + "#{request_uri(env)} " \ "#{byte_xs(env['HTTP_VERSION'])}" + when :request_uri + request_uri(env) when :request_length env['rack.input'].size.to_s when :response_length -- cgit v1.2.3-24-ge0c7