views:

95

answers:

1

I have developed a reverse proxy and currently ONLY process the "html/text" responses from the remote applications, everything else (images, javascript, etc) are passed thru unmodified. The problem I'm having is when the remote site contains javascript that dynamically inserts either java applets or activex controls into the page, as this occurs AFTER I've processed the response and changed all of the URI's.

So for example:

You navigate to the reverse proxy to access remotesite18:

http://reverseproxy.tld/remotesite18

the reverse proxy then makes a call to remotesite18:

http://remotesite18.mysites.tld/

the response has links in the HTML which are modified: from

<a href="/images/banner.jpg" />

to

<a href="http://reverseproxy.tld/remotesite18/images/banner.jpg" />

etc.

BUT what happens when javascript dynamically inserts an applet tag with a relative path of:

test.jar

the request might come back as

http://reverseproxy.tld/test.jar

resulting in a 404. i need to route it to:

http://reversproxy.tld/remotesite18/test.jar

So I need to insert my own JavaScript that can reroute these requests. I know that Glype does this to a certain extent, but I haven't been able to pinpoint how.

Any help is greatly appreciated.

+1  A: 

When you process the response, instead of fixing all of the URIs individually, could you not add a single base URI to the head of the document?

<base href="http://reverseproxy.tld/remotesite18/" />

This would then allow any relative URIs that are processed dynamically to be resolved correctly against your reverse proxy. It also has the benefit of less processing being necessary on your part to modify documents.

Phil Booth
this was a useful tip, but in the end wasn't the problem. I found that the server was returning the wrong content type for the JS files, "text/html" instead of "text/javascript", so the files were going thru my parser...
arri.me