Another quick note on WEBrick: it will only let you stream a response body
if it is an instance of the concrete 'IO' class.

    def send_body(socket)
      case @body
      when IO then send_body_io(socket)
      else send_body_string(socket)
      end
    end

However I'd like to be able to stream out a member of a zipfile: see
http://rubyzip.sourceforge.net/classes/Zip/ZipFileSystem.html. Opening a
zipfile in this way gives you an object which looks and works like a File,
but it's not a subclass of IO.

A simple change to duck-typing and it works:

    def send_body(socket)
      if @body.respond_to?(:read) then send_body_io(socket)
      else send_body_string(socket)
      end
    end

I suppose you can argue there are other classes which respond to :read for
which send_body_io isn't useful - but I think they're equally unlikely to
work with send_body_string either. If you're paranoid, you could test for
the existence of a dummy module, let's say WEBrick::Streamable.

    def send_body(socket)
      case @body
      when IO, Streamable then send_body_io(socket)
      else send_body_string(socket)
      end
    end

Unfortunately, either approach currently means monkey-patching WEBrick.

Regards,

Brian.