Appendix C: Scripts : Predefined Commands
 
Predefined Commands
Table 129 provides syntax, usage, and examples of the predefined commands that are useful for writing scripts.
Table 129: Predefined commands
Syntax
Usage and Example
General
debug(“msg”, …)
Write the message to the debug buffer. For example:
debug("HTTP Request method is %s.\n", HTTP:method_get())
 
Debug strings can be written to the console when the event is triggered. This is helpful when you are testing your scripts.
To enable debug strings to be written to the console, use the following CLI commands:
diagnose debug enable
diagnose debug application haproxy scripting
routing(content_route)
Select a content route. For example:
routing("content2")
content2 is the name of a content route configuration object.
HTTP
header_get_names()
Return a table that contains the names of the HTTP headers. The index is the header name, value. The value is the last value of the header. For example:
--use header and value
headers = HTTP:header_get_names()
for k, v in pairs(headers) do
debug("The value of header %s is %s.\n", k, v)
end
 
--only use the header name
for name in pairs(headers) do
debug("The request/response includes header %s.\n", name)
end
header_get_values(header_name)
Return a table that contains the value of the header "header_name". The index is the header name, value. The value is enquoted (""). Only the key is used. For example:
cookies = HTTP:header_get_values("Cookie")
for cookie in pairs(cookies) do
debug("The request includes cookie %s.\n", cookie)
end
header_get_value(header_name)
Return a string that contains the last occurrence of the header "header_name". For example:
host = HTTP:header_get_value("Host")
header_remove(header_name)
Remove the header "header_name". For example:
HTTP:header_remove("Cookie")
header_insert(header_name, value)
Insert the header "header_name" with value "value". For example:
HTTP:header_insert("Cookie", "cookie=server1")
header_replace(header_name, value)
Replace the value of header "header_name" with value "value". For example:
HTTP:header_replace("Host", "www.fortinet.com")
header_exists(header_name)
Return true when the header "header_name" exists. For example:
if HTTP:header_exists("Cookie") then
end
header_count(header_name)
Return the integer counter of the header "header_name". For example:
count = HTTP:header_count("Cookie")
method_get()
Return the string of the HTTP request method. For example:
method = HTTP:method_get()
method_set(value)
Set the HTTP request method to the string "value". For example:
HTTP:method_set("POST")
path_get()
Return the string of the HTTP request path. For example:
path = HTTP:path_get()
path_set(value)
Set the HTTP request path to the string "value". For example:
HTTP:path_set("/other.html")
uri_get()
Return the string of the HTTP request URI. For example:
uri = HTTP:uri_get()
uri_set(value)
Set HTTP request URI to the string "value". For example:
HTTP:uri_set("/index.html?value=xxxx")
query_get()
Return the string of the HTTP request query. For example:
query = HTTP:query_get()
query_set(value)
Set HTTP request query to the string "value". For example:
HTTP:query_set("value=xxx")
redirect(“URL”, …)
Redirect to the URL. For example:
Host = HTTP:header_get_value("host")
Path = HTTP:path_get()
HTTP:redirect("https://%s%s", Host, Path)