Middleman is not only a powerful proxy server, it may also be used to accelerate and filter responses from an HTTP server. This can be accomplished using the redirect feature. To do this, simply make a redirect entry with a URL pattern that only matches the file portion of a URL, and a redirect URL that points to your Web server. You can utilize the full power of regular expression to perform various tricks such as correcting any 302 redirects the server sends back to point back to the proxy. Lets look at an example setup:
The Proxy server is running on address leenux.ath.cx port 80
The Web server is running on address 192.168.0.1 port 8000
First, add a redirect entry with the URL “/(.*)”, the “(.*)” portion of that is to capture the file that is requested.
Next, fill in the Redirect field with the URL of the Web server your going to redirect to, in this case “http://192.168.0.1/$1”, the $1 is used in regular expression to reference the first string captured using brackets. You will also need to fill in the port option with the Web server's port, in this case 100.
Uncheck the “302 redirect” option, this will cause Middleman to connect directly to the host and process the content rather than just sending back a 302 redirect instruction to the Web browser.
You may also want to have Middleman alter the Location header in any redirects the Web server sends back so they point to the proxy server. To do this, add another redirect entry and fill in the URL with a pattern which would match the Location header sent back. Lets assume our Web server thinks it's hostname is “intranet”; you would fill in the URL field with “http://internal/(.*)”, again we use “(.*)” to capture the file. Next, fill in the Redirect field with Middleman's hostname, in this case “http://leenux.ath.cx/$1”. Make sure to select “Location header” in the “Applies to” option.
Now Middleman should be forwarding all HTTP requests to the Web server, and processing the content as per the entries in other sections.