Inspecting HTTP request parametersAn HTTP request contains a number of different parameters: GET /search?hl=en&q=ZXTM&btnG=Google+Search HTTP/1.1 Host: www.google.com User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0 Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive Referer: http://www.google.com/ Cookie: PREF=4; recall=true; AdSenseLocale=en_US There are a number of TrafficScript functions that make it easy to get and set each of these parameters when ZXTM is processing a request: Inspecting the first line $method = http.getMethod(); # returns 'GET' $rawurl = http.getRawURL(); # returns '/search?hl=en&q=ZXTM&btnG=Google+Search' $path = http.getPath(); # returns '/search' $querystr = http.getQueryString(); # returns 'hl=en&q=ZXTM&btnG=Google+Search' $version = http.getVersion(); # returns '1.1' Inspecting headers $host = http.getHeader( "Host" ); # returns 'www.google.com' $cookie = http.getHeader( "Cookie" ); # returns 'PREF=4; recall=true; AdSenseLocale=en_US' $adlocale = http.getCookie( "AdSenseLocale" ); # returns 'en_US' Other functions
# An HTTP request may contain an additional POST body
$body = http.getBody();
# Iterate through a multipart POST body
$count = 0;
while( $data = http.getMultipartAttachment( $count ) ) {
...
$count = $count + 1;
}
# Get a form parameter - this function inspects both the query string
# and the POST body to look up the form parameter
$searchterm = http.getFormParam( "q" );
Most of these functions have counterparts to set the value, delete it or to test if it exists. For example: http.setHeader( "Host", "www.zeus.com" ); # set the host header http.removeHeader( "Accept-Encoding" ); # delete the 'Accept-Encoding' header http.setPath( "/secure/index.html" ); # set the URL in the request if( http.headerExists( "Cookie" ) ) .... # did the client provide a Cookie header?
Owen Garrett
[Zeus Dev Team] 01 July 2005
|
Recent Articles
Other Resources
|


