Copyright 2006?

It's that time of the year, when the boss reminds you that you've got to change every single 'Copyright 2006' in the footer of your web pages to 'Copyright 2007'... at midnight, New Year's Eve.

Fear not. With a little TrafficScript™, you can celebrate with everyone else, and lay the guilt on the boss when you return in the New Year.

The trick is to add a TrafficScript response rule that rewrites all of your outgoing web pages, but only after midnight on January 1st:

# First, check the date 
if( sys.time.year() != 2007 ) break;
   
# Now, check it's a web page
$contenttype = http.getResponseHeader( "Content-Type" );
if( ! string.startsWith( $contenttype, "text/html" ) ) break;

The difficult bit is working out which bits of content to rewrite. You can't just change every 2006 to 2007, because there may be lots of dates in the web content that you don't want to change.

For www.zeus.com, the footer of every page says:

Copyright Zeus Technology Ltd. 1995-2006

... and it's in the last 250 bytes of the page (at least, before we insert our Google Analytics tracking code).

The following code reads the entire response and rewrites it on the fly.

Note that 'http.getResponseBody()' deals with all of the awkward HTTP protocol parsing for you, decompressing compressed responses and reassembling chunked transfers for dynamic applications, so you don't need to downgrade the request to HTTP/1.0, disable keepalives, remove Accept-Encoding headers or anything else...

$body = http.getResponseBody();

$start = string.drop( $body, 250 );
$end = string.skip( $body, string.len( $body )-250 );

$end = string.replace( $end, " 1995-2006", " 1995-2007" );

http.setResponseBody( $start . $end );

That's it! Come and visit www.zeus.com in the New Year and check that it's worked!

Happy New Year!

For reference, here's the entire rule:

# First, check the date 
if( sys.time.year() != 2007 ) break;
   
# Now, check it's a web page
$contenttype = http.getResponseHeader( "Content-Type" );
if( ! string.startsWith( $contenttype, "text/html" ) ) break;

$body = http.getResponseBody();

$start = string.drop( $body, 250 );
$end = string.skip( $body, string.len( $body )-250 );

$end = string.replace( $end, " 1995-2006", " 1995-2007" );

http.setResponseBody( $start . $end );
Owen Garrett [Zeus Dev Team] 22 December 2006  Permalink  
Leave a comment ...
Your email address will not be displayed.
Your URL will be displayed.
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.
Options:
 
(Line breaks become <br />)
(Set cookies for name, email & url)
Download Free ZXTM Desktop Edition

Recent Articles

Other Resources



www.zeus.com