Reference an iRule variable in an HTML iFile response
I have a sorry page iRule that serves an html sorry page if no servers are left in the pool and serves another page if a 404 or 5xx is encountered. The 404/5xx portion of the irule tries each server in the pool before actually serving the sorry page.
The site down sorry page displays the url attempted pulled from variables $http_host and $http_uri which are set during the HTTP_REQUEST event
The 404/5xx sorry page displays the url attempted pulled from variables $http_host and $http_uri which are set during the HTTP_REQUEST event. It also displays the http status code from variable $http_status which is set from HTTP::status during the HTTP_RESPONSE event.
The html is all defined in the iRule and served via "HTTP::respond 200 content ".
This all works great.
But I would like to move all the html code into 2 iFiles so we can easily modify the sorry page content without touching the iRule. I have uploaded the 2 html files as iFiles.
The new iRule now has the following 2 HTTP::respond commands:
- HTTP::respond 200 content [ifile get down_html]
- HTTP::respond 200 content [ifile get error_html]
Almost everything works as expected. EXCEPT - when the html code in the iFiles try to use the variables set in the iRule. They each display as plain text.
- $http_host
- $http_uri
- $http_status
Is there a way to get the html code in the iFile to reference the variables set in the iRule?
attached files:
- iRule -sorry.txt
- down.html iFile - down.txt
- error.html iFile - error.txt
- I think the subst Tcl command is closest to what you want:
HTTP::respond 200 content [subst -nocommands -nobackslashes [ifile get error_html]]