How does TrafficScript work?

TrafficScript is the programming language used to create 'rules' in Zeus Traffic Manager.

Rules are run when a new request is recieved from a remote client, and when a new response is generated by a back-end server. When you configure a virtual server, you configure which rules are run on the request, and which are run on the response:

TrafficScript state diagram

A request rule is run when a new request is recieved, and some data is read from the connection. The request rule can instruct Zeus Traffic Manager to read more data, it can modify the request, and then select which servers should be used to direct the request to. Once the request rule completes, the request is 'released' and further data from the client is streamed through to the server.

When Zeus Traffic Manager receives response data from the server, the response rules are run. They can also instruct Zeus Traffic Manager to read more data, modify the response, or even modify the original request and instruct Zeus Traffic Manager to resubmit it if necessary. Then the response rule completes, the response is released and further server data is streamed back to the client.

Persistent protocols such as SMTP or POP3 may send many requests within a single TCP connection. If Zeus Traffic Manager recieves more data from the client as it is streaming server data back, the request-response processing loop restarts. Zeus Traffic Manager will re-run the request rule to process the subsequent request data (unless the 'run-once' setting applies to the rule).

Zeus Traffic Manager's TrafficScript language contains a number of helper functions to make it easy to handle different protocols. For example, the 'request.endsWith()' function can be used to indicate the end of a request; Zeus Traffic Manager will not process any more request data until a response has been recieved from the server. request.sendResponse() can be used if you want to generate a response directly, without sending the request to a back-end server.

Finally, TrafficScript contains a complete set of functions to manage and manipulate HTTP traffic, so a developer does not have to worry about the underlying protocol details. Request and response rules are run once all the HTTP headers have been received, and helper functions are available to inspect and set headers, body data and status codes.

Here are a few of the more commonly used HTTP helper functions:

  • http.getPath() and http.setPath() - get and set the path part of the URL used in the request;
  • http.getQueryString() and http.setQueryString() - get and set the query string used in an HTTP request;
  • http.getHeader() and http.setHeader() - get and set named headers in the request;
  • http.getCookie() and http.setCookie() - get and set cookies in the request;
  • http.getFormParam() - look up a parameter in the query string or POST body of a request;
  • http.getBody() and http.setBody() - Read and set the body of the HTTP request;
  • http.getResponseHeader() and http.setResponseHeader() - get and set named headers in the HTTP response;
  • http.getResponseCookie() and http.setResponseCookie() - get and set cookie values in the response;
  • http.getResponseBody() and http.setResponseBody() - Read and set the response for an HTTP request;
  • http.sendResponse() - generate and send an HTTP response;
Owen Garrett [Zeus Dev Team] 01 July 2005 Bookmark with del.icio.us Post this article to Digg Post this article to reddit Post this article to Facebook Tweet this article 1 comment  

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: John [Visitor] · http://blog.chausstran.com/
thanks for the solution.

John
Permalink 06 June 2006 @ 02:15
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)

Recently...

Other Resources