# Re: Custom WEBrick FileHandler

**URL:** <https://www.ruby-forum.com/t/re-custom-webrick-filehandler/148454>\
**Category:** Ruby\
**Created:** [September 13, 2008, 12:01am UTC](https://www.ruby-forum.com/t/re-custom-webrick-filehandler/148454 "2008-09-13T00:01:16Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![stickstone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6f9a4e/32.png) [@stickstone](https://www.ruby-forum.com/u/stickstone)\
**Post date:** [September 13, 2008, 12:01am UTC](https://www.ruby-forum.com/t/re-custom-webrick-filehandler/148454/1 "2008-09-13T00:01:16Z")

</div>

> 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.
