In Files

  • webrick/accesslog.rb
  • webrick/httpserver.rb

Class/Module Index [+]

Quicksearch

WEBrick::AccessLog

Public Instance Methods

escape(data) click to toggle source
 
               # File webrick/accesslog.rb, line 67
def escape(data)
  if data.tainted?
    data.gsub(/[[:cntrl:]\]+/) {$&.dump[1...-1]}.untaint
  else
    data
  end
end
            
format(format_string, params) click to toggle source
 
               # File webrick/accesslog.rb, line 49
def format(format_string, params)
  format_string.gsub(/\%(?:\{(.*?)\})?>?([a-zA-Z%])/){
     param, spec = $1, $2
     case spec[0]
     when e, i, n, o
       raise AccessLogError,
         "parameter is required for \"#{spec}\"" unless param
       (param = params[spec][param]) ? escape(param) : "-"
     when t
       params[spec].strftime(param || CLF_TIME_FORMAT)
     when %
       "%"
     else
       escape(params[spec].to_s)
     end
  }
end
            
setup_params(config, req, res) click to toggle source

This format specification is a subset of mod_log_config of Apache.

http://httpd.apache.org/docs/mod/mod_log_config.html#formats
 
               # File webrick/accesslog.rb, line 25
def setup_params(config, req, res)
  params = Hash.new("")
  params["a"] = req.peeraddr[3]
  params["b"] = res.sent_size
  params["e"] = ENV
  params["f"] = res.filename || ""
  params["h"] = req.peeraddr[2]
  params["i"] = req
  params["l"] = "-"
  params["m"] = req.request_method
  params["n"] = req.attributes
  params["o"] = res
  params["p"] = req.port
  params["q"] = req.query_string
  params["r"] = req.request_line.sub(/\x0d?\x0a\z/, '')
  params["s"] = res.status       # won't support "%>s"
  params["t"] = req.request_time
  params["T"] = Time.now - req.request_time
  params["u"] = req.user || "-"
  params["U"] = req.unparsed_uri
  params["v"] = config[:ServerName]
  params
end