mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	 52d91fa402
			
		
	
	
		52d91fa402
		
	
	
	
	
		
			
			should log about all accepted socket. [ruby-core:03962] * lib/webrick/accesslog.rb (WEBrick::AccessLog#setup_params): "%%" and "%u" are supported. [webricken:135] * lib/webrick/httpservlet/filehandler.rb (WEBrick::HTTPServlet::FileHandler#check_filename): :NondisclosureName is acceptable if it is Enumerable. * lib/webrick/config.rb (WEBrick::Config::FileHandler): default value of :NondisclosureName is [".ht*", "*~"]. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7566 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
		
			
				
	
	
		
			67 lines
		
	
	
	
		
			2.1 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
			
		
		
	
	
			67 lines
		
	
	
	
		
			2.1 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
| #
 | |
| # accesslog.rb -- Access log handling utilities
 | |
| #
 | |
| # Author: IPR -- Internet Programming with Ruby -- writers
 | |
| # Copyright (c) 2002 keita yamaguchi
 | |
| # Copyright (c) 2002 Internet Programming with Ruby writers
 | |
| #
 | |
| # $IPR: accesslog.rb,v 1.1 2002/10/01 17:16:32 gotoyuzo Exp $
 | |
| 
 | |
| module WEBrick
 | |
|   module AccessLog
 | |
|     class AccessLogError < StandardError; end
 | |
| 
 | |
|     CLF_TIME_FORMAT     = "[%d/%b/%Y:%H:%M:%S %Z]"
 | |
|     COMMON_LOG_FORMAT   = "%h %l %u %t \"%r\" %s %b"
 | |
|     CLF                 = COMMON_LOG_FORMAT
 | |
|     REFERER_LOG_FORMAT  = "%{Referer}i -> %U"
 | |
|     AGENT_LOG_FORMAT    = "%{User-Agent}i"
 | |
|     COMBINED_LOG_FORMAT = "#{CLF} \"%{Referer}i\" \"%{User-agent}i\""
 | |
| 
 | |
|     module_function
 | |
| 
 | |
|     # This format specification is a subset of mod_log_config of Apache.
 | |
|     #   http://httpd.apache.org/docs/mod/mod_log_config.html#formats
 | |
|     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/o, '')
 | |
|       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
 | |
| 
 | |
|     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
 | |
|            params[spec][param] || "-"
 | |
|          when ?t
 | |
|            params[spec].strftime(param || CLF_TIME_FORMAT)
 | |
|          when ?%
 | |
|            "%"
 | |
|          else
 | |
|            params[spec]
 | |
|          end
 | |
|       }
 | |
|     end
 | |
|   end
 | |
| end
 |