How to Configure a NetScaler Appliance to Resend an HTTP Request

How to Configure a NetScaler Appliance to Resend an HTTP Request

book

Article ID: CTX122335

calendar_today

Updated On:

Description

This article describes how to configure a NetScaler appliance to resend a client HTTP request based on the previous response of a server.

Requirements

A Citrix NetScaler running version 9.0 or later

Background

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.


Instructions

The following procedure assumes that you are creating load balancing Virtual Servers and individual services. If you are configuring Content Switching Virtual Servers or service groups, make the appropriate substitutions.
  1. 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)

  2. 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.

  3. 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).

  4. 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.

  5. 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

Example:
 
en feature lb rewrite
add service "black" 192.168.100.10 HTTP 80
add lb vserver "main-lb-vs" HTTP 10.0.0.1 80
bind lb vserver "main-lb-vs" "black"
add service "red" 192.168.200.1 HTTP 80
add lb vserver "resend_lb_vs" http 0.0.0.0 0
bind lb vserver "resend_lb_vs" "red"
add policy httpCallout callout_retry_pol
set policy httpCallout callout_retry_pol -vServer "resend_lb_vs" -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(64000)"
add rewrite action resend_rewrite_action replace_http_res "SYS.HTTP_CALLOUT(callout_retry_pol)" -bypassSafetyCheck YES
add rewrite policy "resend_rewite_policy" "HTTP.RES.STATUS.BETWEEN(500,510)" "resend_rewrite_action"
bind lb vserver "main-lb-vs" -policyName resend_rewite_policy -priority 1 -gotoPriorityExpression END -type RESPONSE
  • In the a preceding example, if a request is made to the "main-lb-vs" and the server “black” responds with an HTTP response code between 500 and 510 inclusive, the NetScaler resends the request to the resend_lb_vs vserver, which then goes to the service (server) “red”. The response from the server “red” is sent to the client regardless of its contents.
  • Note that this configuration increases the resource utilization of the NetScaler, the extent of which is dependent upon your environment and how many requests are resulting in the HTTP callout. It is recommended to take baseline measurements of the NetScaler resource utilization before and after making these configuration changes.
  • You can add more retries by creating additional virtual servers and httpCallout policies referencing these virtual servers.
  • It is recommended that you do not configure httpCallout policies and virtual servers in such a way as to create a loop. Examples of this would be an HTTP callout policy referencing the same load balancing virtual server to which it is bound through the rewrite policy and action, or one HTTP callout policy referencing virtual server “A” and bound to virtual server “B”, and another HTTP callout policy referencing virtual server “B” and bound to virtual server “A”. In these cases, failed client requests could loop back and forth between the NetScaler and servers, greatly increasing the load on the environment.

Issue/Introduction

This article describes how to configure a NetScaler appliance to resend a client HTTP request based on the previous response of a server.

Additional Information

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