Ruby on Rails
HowToRenderProxiedPages

NOTE: I needed this information but this page has been eaten by spam for a long time, and was imported from the old wiki after the crash but never cleaned up. The best copy I could find with version 5. I took it into a text editor and cleaned it up.

Sometimes you may want to render a page from another source (perhaps an internal server, visible to your webserver but not to the internet at large), either as is or with some editing.

This is quite easy in Rails. On this page I’ll walk you through the development of a fairly complete proxy wrapper (which at the time of this writing is being used to HowToWrapRailsAroundAnExistingApplication). If your needs are simple, you may want to just grab one of the early examples, and stop reading as soon as we’ve gotten to the fuctionality you need. If your needs are urgent, you may want to just jump to the end and grab the finished product.

But if you want to understand how it all works, feel free to follow along as I “program out loud[1]”.


A simple example


Handling HTTP POST, HEAD, etc. requests


Alternate ports


Handling redirection


Handling cookies


Propogating errors


Sanity checking the requests


Filtering the results


A note about efficiency

You may want to cache images locally…

1 And since this is a Wiki, you can even interrupt to ask questions!

2 The whole goal of good engineering is to increase the chance that you will be “lucky” at any given point in the future.

category: Howto