Is it possible in WEBrick to make a FileHandler with some elements of
page changed in a custom way? For example, could I have the file sizes
displayed in KB, or in red font? Is it possible to intercept the
response page creation process, without changing its main functionality?
I presume you’re talking about when WEBrick returns a directory listing?
Your best bet with WEBrick (I’ve learned) is to find your way around the
source. Under your Ruby lib directory, typically /usr/lib/ruby/1.8, the
file
you need to look at is webrick/httpservlet/filehandler.rb
Look at the method set_dir_list in the FileHandler class. There doesn’t
seem
to be any hook for changing the formatting, but nothing stops you
overwriting set_dir_list with your own version.
require ‘webrick’
class WEBrick::HTTPServlet::FileHandler
def set_dir_list
… copy-paste the original method here
… then modify it
end
end
Or you could subclass FileHandler to make a new class.
Regards,
Brian.