tags:

views:

203

answers:

3

We are attempting to rewrite some URLs in our response for an outside proxy server. We noticed that the response is being broken up as it goes through the response filter. We then use regular expressions to locate the URLs and rewrite them. The issue we ran into is that the way that it is broken up (not exactly sure how it gets segmented), we had one URL that was being cut in half between the chunks, and so our regular expression didn't pick it up in either chunk and it was not rewritten.

Ex.

End of Chunk1

"...<body><a href="http://myserver.local/"&gt;

Start of Chunk2

"path/file.aspx">Some link</a>..."

So our regular expression doesn't pick up the link as a valid URL. We tried pooling our response into a StringBuilder to make sure we have the whole response before we attempt to rewrite the URLs, but that is resulting in the viewstate being corrupted. Any ideas?

A: 

On the Java platform I use (sorry, not familiar with asp.net) we write our URLs using a utility method. This way the url rewriting can hook into that method and rewrite entire urls.

The advantage is that it can be done very efficiently. The disadvantage is that you can never just put a bare url in the HTML, you always have to use the helper method. However, for J2EE this is considered a normal best practice, so the overhead wasn't much in our case.

To implement the rewriting, we have a filter which wraps the http response and overrides the encodeURL method. I'm not sure if .net has a similar concept.

Mr. Shiny and New
If .NET has a similar concept or if there is a better way to handle this, I am open to change. I would prefer to handle this in a filter so that we don't have to change every page in our website to wrap each URL. Seems like there should be a better solution.
A: 

If performance is critical, you may want to use your own implementation of a DFA scanner.

A tool to create the tables needed would be for instance the GOLD Parsing System (just skip the LALR stuff, which would process the grammar out of tokens found by the DFA scanner).

Lucero
A: 

How are your hyperlinks being generated? If you're using ASP.Net link controls to generate your URLs; you could just subclass the link control with a custom link control. This new link control, upon detecting the proxy, would rewrite your links on the fly; so the links are altered as needed before the HTML is even generated.

Frank Rosario