Rewriting HTTP responsesSuppose that you wanted to publish an internal website (http://intranet.mycorp.com/) so that it can be accessed externally (with the correct access controls and security of course!). However, the domain name One key requirement is to rewrite any HTML that includes references to # We only want to process text/html responses (ie, not images or other types) if( http.getResponseHeader( "Content-Type" ) != "text/html" ) break; $response = http.getResponseBody(); # replace 'http://intranet.mycorp.com/' with 'https://extranet.mycorp.com/' $response = string.regexsub( $response, "http://intranet.mycorp.com/", "https://extranet.mycorp.com/", "g" ); http.setResponseBody( $response );
Owen Garrett
[Zeus Dev Team] 01 July 2005
Comments:This public messageboard is not a forum for technical support. To report technical support problems, please contact our dedicated Support team using the instructions at the bottom of this page.
Comment from:
Steven Bibby [Visitor]
The second line of the code sample above has an extra bracket, and should read as below:-
if( http.getResponseHeader( "Content-Type" != "text/html" ) ) break;
Comment from:
Owen Garrett [Zeus Dev Team]
Thanks for that - well spotted. I've corrected the article.
Owen
Comment from:
Steven Bibby [Visitor]
As per the TrafficScript reference, the result of the http.getResponseHeader( "Content-Type" ) function could be something like 'text/html; charset=ISO-8859-1'. If this is the case, then this example will break and not run the string.regexsub.
Do you have an alternative that takes this into account?
Comment from:
Owen Garrett [Zeus Dev Team]
Good point... try using string.startsWith() as follows:
$ct = http.getHeader( "Content-Type" ); or, for more brevity: if( !string.startsWith( http.getHeader( "Content-Type" ), "text/html" ) ) break; [The earlier version of this comment missed the '!' - sorry for any confusion this may have caused]
Comment from:
slyphon [Member]
Unless I'm misinterpreting the desired effect from this code, it would seem that you'd want the *negation* of the above:
if( !string.startsWith( http.getHeader( "Content-Type" ), "text/html" ) ) break; as you want to process "text/html" responses, and not anything else. Or am I being dense?
Comment from:
Owen Garrett [Zeus Dev Team]
No - you're exactly correct! Thank you for pointing that out.
I've updated the comment above so that the code is now correct.
Comment from:
Adam Daughterson [Visitor]
This is great for TrafficScript, but I'm not finding any way to do this with RuleBuilder and ZXTM complains that TrafficScript rules cannot be run under my current license. Any help?
Thanks in advance, AD
Comment from:
Owen Garrett [Zeus Dev Team]
This type of capability is only available via TrafficScript, not RuleBuilder. You may have a ZXTM LB license (which just permits RuleBuilder), rather than a full ZXTM license.
|
Recent Articles
Other Resources
|


