This article describes how to configure a NetScaler appliance to resend a client HTTP request based on the previous response of a server.
A Citrix NetScaler running version 9.0 or later
If an HTTP server is unable to deliver the desired Web page to a client request, then the HTTP server might instead send an error message. Some examples of these error messages are “404 Not Found”, “500 Internal Server Error”, and “503 Service Unavailable”. Additionally, there might be custom error pages returned from the server, for instance a “sorry page” delivered using the HTTP code “200 OK”.
Under normal operation, if a NetScaler appliance receives an error message from the server in response to a client request, then the appliance passes this message to the client. The client must then re-try the HTTP request if necessary.
Using the HTTP callout feature in the NetScaler software release 9.0 and later, you can configure the NetScaler to resend the same client request depending on the previous server response, and then send the resulting page to the client.
Create the services and a Virtual Server in the appliance to receive the client HTTP requests, if they do not already exist (this is the main virtual server).
add service "<SERVICE_NAME>" <SERVER_IP_or_NAME> HTTP <PORT>
(repeat for all services)
add lb vserver "<MAIN_VSERVER_NAME>" <VSERVER_IP> <PORT>
bind lb vserver "<MAIN_VSERVER_NAME>" "<SERVICE_NAME>"
(repeat for all services)
Configure a Virtual Server to receive the resent client HTTP requests:
add service "<SERVICE_NAME>" <SERVER_IP_or_NAME> HTTP <PORT>
(repeat for all services)
add lb vserver "<RESEND_VSERVER_NAME>" <RESEND_VSERVER_IP> <PORT>
bind lb vserver "<RESEND_VSERVER_NAME>" "<SERVICE_NAME>"
(repeat for all services)
These services can be similar to the services in step 1, or can be different. If these services are the same, note that this might result in the request being resent to the same server that had previously sent a bad response.
Configure the HTTP Callout policy:
add policy httpCallout <CALLOUT_POLICY_NAME>
set policy httpCallout <CALLOUT_POLICY_NAME> -vServer "<RESEND_VSERVER_NAME>" -returnType TEXT -fullReqExpr q{"GET " + http.req.url + " HTTP/" + http.req.version.major + "." + http.req.version.minor.sub(1) + "\r\nAccept:*/*\r\n\r\n"} -resultExpr "HTTP.RES.FULL_HEADER+HTTP.RES.BODY(###)"
The value contained in the parentheses in the HTTP.RES.BODY(###) variable must be a number that is as large or larger than the desired response page size (not the failure page size), otherwise the response that the client receives is truncated to the length specified by this number. You must determine this value based on the size(s) of the server response(s).
Configure a rewrite policy and action to trigger the HTTP callout:
add rewrite action "<REWRITE_ACTION_NAME>" replace_http_res "SYS.HTTP_CALLOUT(<CALLOUT_POLICY_NAME>)" -bypassSafetyCheck YES
add rewrite policy "<REWRITE_POLICY_NAME>" "<RULE>" "<REWRITE_ACTION_NAME>"
The <RULE> is where you define the parameters that control the resending of the request. For instance, to resend the client request if the server HTTP response status code is “404 Not Found”, you could use the rule "HTTP.RES.STATUS.EQ(404)". If you want to resend the client request based on the word “We are sorry” in the first 100 bytes of the resulting Web page, you could use the rule “HTTP.RES.BODY(100).CONTAINS(\"We are sorry\")”. For more information on writing policies, see the “Policy Configuration and Reference Guide” for NetScaler 9.0.
Bind the rewrite policy to the MAIN load balancing virtual server:
bind lb vserver "<MAIN_VSERVER_NAME>" -policyName <REWRITE_POLICY_NAME> -priority <PRIORITY> -type RESPONSE
See the chapter on “HTTP Service Callout” in the Citrix NetScaler AppExpert Guide for NetScaler 9.0 or 9.1
CTX121835 - Citrix NetScaler AppExpert Guide - Release 9.1
CTX121836 - Citrix NetScaler AppExpert Guide - Release 9.0
See the Policy Configuration and Reference Guide for NetScaler 9.0 or 9.1
CTX121824 - Citrix NetScaler Policy Configuration and Reference Guide - Release 9.1
CTX119204 - Citrix NetScaler Policy Configuration and Reference Guide - Release 9.0