Mongrel Raw Output GemPlugin

This GemPlugin allows you to specify a special header, 'X-Raw-Output', to make Mongrel output the body of a response as the entire response. This allows you to have full manual control over the http headers and body from any application (Rails, Camping, etc). I've found this useful when mocking the full http response of a foreign server when developing and testing bots and scrapers.

The Mongrel Raw Output Rubyforge page

Installation

Couldn't be easier: gem install mongrel_raw_output

Or you can use subversion: svn checkout svn://rubyforge.org/var/svn/mongrel-raw-out/trunk

Usage

In Rails the best way to use the Raw Output GemPlugin is with a file called mongrel_raw_output.conf in your config directory. Its contents should look like this:

uri "/",
 :handler => plugin("/handlers/rawoutput"),
 :in_front => false

Then start your Mongrel like this:

  mongrel_rails start -S config/mongrel_raw_output.conf
In Rails, you can add this method to application.rb:
# send the raw text directly to the client
def render_raw raw
  render :text => raw
  headers['X-Raw-Output'] = true
end

Thanks

Thanks to Zed Shaw for the encouragement to turn my nasty hack into maintainable, compatible code. I tend to write these things cause I need them, and then when I don't need them anymore, I let them go fallow, so if you find yourself using Mongrel Raw Output, and there are bugs or features you want to add, please email me so I can roll them back into trunk.

jchris :: mfdz : com