views:

41

answers:

2

That is to say, let's say I'm writing something that's hosted on foo.com. I'd like it to be possible for a user who goes to foo.com/bar.com to be served up bar.com from foo.com and to be able to interact with bar.com (e.g. navigate to foo.com/bar.com/baz via point-and-click). I understand that this is what a proxy is supposed to do. I need to do some preprocessing of a request to access the proxy, which is why I'm turning to a web framework. I've a preference for django, rails, or sinatra, or another python/ruby solution, but any will do, really.

Thanks in advance; alternate suggestions are welcome.

A: 

i can only talk about django, but....

if you only want to use the same object/data on multiple websites you should have a look at the django sites framework

for redirects i would suggest the redirects app

or you simply use the redirect shortcut in your views

renton
The site whose proxy I am mirroring (bar.com) is not under my control. I don't want to redirect the user, I want the server to download the content and pass it onto the user (acting as a proxy).
aresnick
A: 

First you will need to parse the URL at foo.com. In django you could have an url like this(not tested):

url(r'(?P<url>.*)$', my_proxy_view, name = 'proxy')

So http://foo.com/bar.com/baz/ will give you an url of 'bar.com/baz/' you may use as you please in your view.

Then you have to retrieve the page at bar.com, using a library like urllib2.

When you have the contents of the remote page, you need to change all links(anchor elements) that point to bar.com to point to the URLs of your proxy. If you want to proxy images, stylesheets and javascript you need to change the links of those as well.

You probably want to cache as much as possible as well. And be sure to set a user-agent on the urllib request that will let the other site know that this is some kind of robot or proxy.


With that said, this sounds like a really stupid idea. What is your use case?

knutin
Yeah, it is pretty silly, I know. I'd like to set up a mirror of a proxy that's behinds a web-based authentication gateway. I can emulate a browser to fill out the web-based authentication, but I want it to then act as a proxy. . .so, it looks something like:[user's browser] --- [my web server] --- [web gateway/form] --- [remote proxy] --- [remote resource (whatever the user requested)]. I may also be able to solve the problem by running a server on a VPN or figuring out how to publicly expose SSH tunneling to a proxy.
aresnick
See [this](http://stackoverflow.com/questions/2277557/how-can-i-set-up-a-proxy-server-to-mirror-an-existing-proxy-server-which-has-a-we) and [this](http://serverfault.com/questions/117564/how-can-i-set-up-squid-to-act-as-a-tunneling-proxy-to-expose-a-vpn-or-ssh-tunnel) and [this](http://serverfault.com/questions/114470/mirroring-an-existing-proxy-which-is-behind-a-browser-based-authentication) and [this](http://serverfault.com/questions/116372/how-can-i-set-up-a-proxy-server-to-mirror-a-vpn-connection) for details.
aresnick