lib/heel/dir_handler.rb in heel-0.3.2 vs lib/heel/dir_handler.rb in heel-0.4.0
- old
+ new
@@ -183,15 +183,16 @@
end
entries << entry_data
end
entries = entries.sort_by { |e| e.link }
-
+ res_bytes = 0
response.start(200) do |head,out|
head['Content-Type'] = 'text/html'
- out.write(template.result(binding))
+ res_bytes = out.write(template.result(binding))
end
+ return res_bytes
end
# this method is essentially the send_file method from
# Mongrel::DirHandler
def respond_with_send_file(path,method,request,response)
@@ -227,10 +228,11 @@
response.send_header
if method == ::Mongrel::Const::GET then
response.send_file(path,stat.size < ::Mongrel::Const::CHUNK_SIZE * 2)
end
+ return stat.size
end
# process the request, returning either the file, a directory
# listing (if allowed) or an appropriate error
def process(request, response)
@@ -241,24 +243,34 @@
req_path = File.expand_path(File.join(@document_root,
::Mongrel::HttpRequest.unescape(request.params[Mongrel::Const::PATH_INFO])),
@document_root)
res_type = how_to_respond(req_path)
-
+ res_size = 0
+
case res_type
when :directory_listing
- respond_with_directory_listing(req_path,request,response)
+ res_size = respond_with_directory_listing(req_path,request,response)
when String
- respond_with_send_file(res_type,method,request,response)
+ res_size = respond_with_send_file(res_type,method,request,response)
when Integer
response.status = res_type
end
+
# invalid method
else
response.start(403) { |head,out| out.write("Only HEAD and GET requests are honored.") }
end
+ log_line = [ request.params[Mongrel::Const::REMOTE_ADDR], "-", "-", "[#{Time.now.strftime("%d/%b/%Y:%H:%M:%S %Z")}]" ]
+ log_line << "\"#{method}"
+ log_line << request.params['REQUEST_URI']
+ log_line << "#{request.params['HTTP_VERSION']}\""
+ log_line << response.status
+ log_line << res_size
+
+ log log_line.join(' ')
end
# essentially this is strfbytes from facets
def num_to_bytes(num,fmt="%.2f")
case
@@ -276,9 +288,9 @@
"#{num} bytes"
end
end
def log(msg)
- STDERR.print "--> ", msg, "\n"
+ STDERR.print msg, "\n"
end
end
end