Imagine eating a bowl of noodles mixed with rice, curd, bread, corn flakes and milk. It will be a torture to our taste buds to even taste a mix of food like this and try to understand what is what. It’s tough for us to separate all these and relish the desired food amongst all, once they are mixed.

Similarly for NetScaler it becomes really difficult to do specific data processing when everything received is a huge chunk of strings. With Typecast, one of the NetScaler’s AppExpert feature, it becomes easy for NetScaler to know; process and get the desired results out of a bulk of strings received as requests or response!

In other words, Typecasts helps to transform the data in the requests or response with respect to the different data types and enables runtime operation on transformed entities.

There are various types of Typecast methods available in NetScaler. To throw more light on this, we will discuss how some of these important Typecasts Methods function.

  • TYPECAST_LIST_T

TYPECAST_LIST_T treats the strings in the body of an HTTP request or response as a list of elements delimited by a specific character, like “?” as can be seen in the below mentioned example.

Add rewrite action Act_rep REPLACE “HTTP.RES.BODY(100)” “HTTP.RES.BODY(100).TYPECAST_LIST_T(‘?’).GET(1)”

When the below mentioned REQUEST is processed via  Act_rep action it extracts the response data as mentioned below with o9bH`”|6r%Bo as the response data.

REQUEST DATA :

HTTP/1.1 200 OK

Date: Thu, 14 Jul 2011 23:50:56 GMT

Server: Apache/2.2.6 (Fedora)

Last-Modified: Thu, 04 Feb 1999 22:36:50 GMT

ETag: “30374d-32-9a28c480”

Accept-Ranges: bytes

Content-Length: 50

Connection: close

Content-Type: text/html; charset=UTF-8

JLEwx;+?o9bH`”|6r%Bo?CQ\+e?+i^z-.gto&j69?>5b”[($V’

RESPONSE DATA :

HTTP/1.1 200 OK

Date: Thu, 14 Jul 2011 23:50:56 GMT

Server: Apache/2.2.6 (Fedora)

Last-Modified: Thu, 04 Feb 1999 22:36:50 GMT

ETag: “30374d-32-9a28c480”

Accept-Ranges: bytes

Content-Length: 12

Connection: close

Content-Type: text/html; charset=UTF-8

o9bH`”|6r%Bo

In this example, TYPECAST_LIST_T in HTTP.RES.BODY(100).TYPECAST_LIST_T(‘?’) identifies the content with respect to the delimiter “?”. It forms a list of content found within the body of the response, wherever “?” is encountered. The expression: “HTTP.RES.BODY(100).TYPECAST_LIST_T(‘?’).GET(1)” will form a list as mentioned below:

Index Content
0 JLEwx;+
1 o9bH`”|6r%Bo
2 CQ\+e
3 +i^z-.gto&j69
4 >5b”[($V’

The GET(1) part of the expression returns the second content from the list with index 1. When the strings are processed, it forms the list, extracting the content from left to the right direction.

  • TYPECAST_TIME_T

TYPECAST_TIME_T operator identifies the data types with respect to different time formats. Lets understand this better with an example.

Add rewrite policy pol_time ‘HTTP.RES.BODY(100).TYPECAST_TIME_T.CONTAINS(“Jul“)’ action1

When the pol_time policy is evaluated, HTTP.RES.BODY(100).TYPECAST_TIME_T.CONTAINS(“Jul“) expression will return TRUE whenever the response data contains July.

HTTP RESPONSE DATA

HTTP/1.1 200 OK

Date: Fri, 15 Jul 2011 00:13:40 GMT

Server: Apache/2.2.6 (Fedora)

Last-Modified: Fri, 23 Mar 2007 12:34:14 GMT

ETag: “303843-1bf-45f05d80”

Accept-Ranges: bytes

Content-Length: 65

Connection: close

Content-Type: text/html; charset=UTF-8

<html><head>

<title>Date</title>

</head><body>Thu, 14 Jul 2011

</body></html>

The above mentioned policy, checks whether the Packet is sent after the month of July. As can be observed, looking at the body of the HTTP Response, HTTP.RES.BODY(100).TYPECAST_TIME_T.CONTAINS(“Jul“) expression will return TRUE Boolean value and lead to action1 as mentioned in the pol_time policy.

  • TYPECAST_IP_ ADDRESS_T

TYPECAST_IP_ ADDRESS_T operator identifies IP addresses within the strings of requests or responses. For example:

Add rewrite policy IP_policy ‘HTTP.REQ.HEADER(“HOST”).TYPECAST_IP_ADDRESS_T.EQ(10.102.113.53)’ Action_TC_IP

Add rewrite action Action_TC_IP REPLACE_HTTP_RES ‘HTTP.REQ.HEADER(“Host”).TYPECAST_IP_ADDRESS_T + “: Access is not allowed”‘ -bypassSafetyCheck YES

REQUEST:

GET / HTTP/1.1

Host: 10.102.113.53

User-Agent: Mozilla Firefox/3.0.3

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

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

Date:Thu, 14 Jul 2011 18:25:00 GMT

Cookie: sessionid=100xyz

RESULT:

10.102.113.53: Access is not allowed

The above mentioned Action_TC_IP action extracts the host IP address from the header of the request and displays a 10.102.113.53: Access is not allowed message, if the host IP address is 10.102.113.53 according to the IP_policy policy.

If the Host header would have had a different data type than IP address, then it wouldn’t have returned 10.102.113.53: Access is not allowed message.

  • TYPECAST_HTTP_URL_T

TYPECAST_HTTP_URL_T method identifies the URL data type and helps in extracting the relevant information from within the URL. Elaborating with an example:

Add rewrite action version_as_query2 replace “HTTP.REQ.URL.QUERY.VALUE(\”Version\”)” HTTP.REQ.VERSION.TYPECAST_HTTP_URL_T.AFTER_STR(“HTTP/”) -bypassSafetyCheck YES

HTTP REQUEST DATA

GET http://10.102.113.53/testsite/cookie_path.asp?dhdhd-dkid=34&Version=ddd&fh=fdhjddh&cjcdjcd=dkj HTTP/1.1

Host: 10.102.113.53

User-Agent: Mozilla Firefox/3.0.3

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

Accept-Language: en-us,en;q=0.5

Accept-Encoding: gzip,deflate\r\n

Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7

Keep-Alive: 300

Connection: keep-alive

Date: Thu, 14 Jul 2011 20:25:00 GMT

Cookie: sessionid=100xyz

RESULT

GET http://10.102.113.53/testsite/cookie_path.asp?dhdhd-dkid=34&Version=1.1&fh=fdhjddh&cjcdjcd=dkj HTTP/1.1

Host: 10.102.113.54

User-Agent: Mozilla Firefox/3.0.3

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

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

Date: Thu, 14 Jul 2011 20:25:00 GMT

Cookie: sessionid=100xyz

As can be seen with the above mentioned example, the version_as_query action extracts the value “Version” from within the query and assigns 1.1 to the version value, in the response.

  • TYPECAST_NUM_T

TYPECAST_NUM_T method identifies the numeric data type within the requests or the responses. For example,

Add rewrite action Act1 insert_http_header Company “HTTP.REQ.URL.QUERY.TYPECAST_NUM_T(DECIMAL).ADD(4)”

HTTP REQUEST

GET http://10.102.113.53/testsite/cookie_path.asp?674444 HTTP/1.1

Host:10.102.113.53

User-Agent: Mozilla Firefox/3.0.3

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

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

Date: Thu, 15 Jul 2011 03:01:00 GMT

Cookie: sessionid=100xyz

RESULT

GET http://10.102.113.53/testsite/cookie_path.asp?674444 HTTP/1.1

Host:10.102.113.53

User-Agent: Mozilla Firefox/3.0.3

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

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

Date: Thu, 14 Jul 2011 03:01:00 GMT

Cookie: sessionid=100xyz

Company: 674448

With the above mentioned example, when the Act1 action is processed by the incoming REQUEST, we extract the number 674444 in this case, within the query and we add 4 to the number extracted with the ADD(4) function within the HTTP.REQ.URL.QUERY.TYPECAST_NUM_T(DECIMAL).ADD(4) expression.  Act1 action is inserting an HTTP header Company: 674448 with the value calculated by the expression within the defined action.

These were the few examples of Typecasts methods. There are many others mentioned below.

  • <text>.TYPECAST_ NVLIST_T(<separator>, <delimiter>)
  • <numeric string>.TYPECAST_IPV6_ADDRESS_T
  • <text>.TYPECAST_HTTP_ HOSTNAME_T
  • <text>.TYPECAST_HTTP_ METHOD_T
  • <text>.TYPECAST_DNS_ DOMAIN_T
  • <text>.TYPECAST_HTTP_ HEADER_T(“<name>”)
  • <text>.TYPECAST_COOKIE_T
  • <number>.TYPECAST_DOUBLE_AT
  • <number>.TYPECAST_IP_ADDRESS_AT
  • <number>.TYPECAST_TIME_AT
  • <number>.TYPECAST_TIME_AT.BETWEEN(<time1>, <time2>)
  • <number>.TYPECAST_TIME_AT.DAY
  • <number>.TYPECAST_TIME_AT.EQ(<t>)
  • <number>.TYPECAST_TIME_AT.GE(<t>)
  • <number>.TYPECAST_TIME_AT.GT(<t>)
  • <number>.TYPECAST_TIME_AT.HOURS
  • <number>.TYPECAST_TIME_AT.LE(<t>)
  • <number>.TYPECAST_TIME_AT.LT(<t>)
  • <number>.TYPECAST_TIME_AT.MINUTES
  • <number>.TYPECAST_TIME_AT.MONTH
  • <number>.TYPECAST_TIME_AT.RELATIVE_BOOT
  • <number>.TYPECAST_TIME_AT.RELATIVE_NOW
  • <number>.TYPECAST_TIME_AT.SECONDS
  • <number>.TYPECAST_TIME_AT.WEEKDAY
  • <number>.TYPECAST_TIME_AT.WITHIN(<time1>, <time2>)
  • <number>.TYPECAST_TIME_AT.YEAR
  • <prefix>.TYPECAST_NUM_AT
  • <prefix>.TYPECAST_DOUBLE_AT
  • <prefix>.TYPECAST_UNSIGNED_LONG_AT
  • <prefix>.TYPECAST_NUM_T(<type>,<default>)
  • <prefix>.TYPECAST_UNSIGNED_LONG_T(<type>)
  • <prefix>.TYPECAST_UNSIGNED_LONG_T(<type>,<default>)