.\" Man page generated from reStructuredText. . .TH "HAPROXY-LUA" "1" "Apr 10, 2023" "1.0" "haproxy-lua" .SH NAME haproxy-lua \- haproxy-lua Documentation . .nr rst2man-indent-level 0 . .de1 rstReportMargin \\$1 \\n[an-margin] level \\n[rst2man-indent-level] level margin: \\n[rst2man-indent\\n[rst2man-indent-level]] - \\n[rst2man-indent0] \\n[rst2man-indent1] \\n[rst2man-indent2] .. .de1 INDENT .\" .rstReportMargin pre: . RS \\$1 . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin] . nr rst2man-indent-level +1 .\" .rstReportMargin post: .. .de UNINDENT . RE .\" indent \\n[an-margin] .\" old: \\n[rst2man-indent\\n[rst2man-indent-level]] .nr rst2man-indent-level -1 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]] .in \\n[rst2man-indent\\n[rst2man-indent-level]]u .. .SH HAPROXY LUA RUNNING CONTEXTS .sp The Lua code executed in HAProxy can be processed in 2 main modes. The first one is the \fBinitialisation mode\fP, and the second is the \fBruntime mode\fP\&. .INDENT 0.0 .IP \(bu 2 In the \fBinitialisation mode\fP, we can perform DNS solves, but we cannot perform socket I/O. In this initialisation mode, HAProxy still blocked during the execution of the Lua program. .IP \(bu 2 In the \fBruntime mode\fP, we cannot perform DNS solves, but we can use sockets. The execution of the Lua code is multiplexed with the requests processing, so the Lua code seems to be run in blocking, but it is not the case. .UNINDENT .sp The Lua code is loaded in one or more files. These files contains main code and functions. Lua have 6 execution context. .INDENT 0.0 .IP 1. 3 The Lua file \fBbody context\fP\&. It is executed during the load of the Lua file in the HAProxy \fI[global]\fP section with the directive \fIlua\-load\fP\&. It is executed in initialisation mode. This section is use for configuring Lua bindings in HAProxy. .IP 2. 3 The Lua \fBinit context\fP\&. It is a Lua function executed just after the HAProxy configuration parsing. The execution is in initialisation mode. In this context the HAProxy environment are already initialized. It is useful to check configuration, or initializing socket connections or tasks. These functions are declared in the body context with the Lua function \fIcore.register_init()\fP\&. The prototype of the function is a simple function without return value and without parameters, like this: \fIfunction fcn()\fP\&. .IP 3. 3 The Lua \fBtask context\fP\&. It is a Lua function executed after the start of the HAProxy scheduler, and just after the declaration of the task with the Lua function \fIcore.register_task()\fP\&. This context can be concurrent with the traffic processing. It is executed in runtime mode. The prototype of the function is a simple function without return value and without parameters, like this: \fIfunction fcn()\fP\&. .IP 4. 3 The \fBaction context\fP\&. It is a Lua function conditionally executed. These actions are registered by the Lua directives "\fIcore.register_action()\fP". The prototype of the Lua called function is a function with doesn\(aqt returns anything and that take an object of class TXN as entry. \fIfunction fcn(txn)\fP\&. .IP 5. 3 The \fBsample\-fetch context\fP\&. This function takes a TXN object as entry argument and returns a string. These types of function cannot execute any blocking function. They are useful to aggregate some of original HAProxy sample\-fetches and return the result. The prototype of the function is \fIfunction string fcn(txn)\fP\&. These functions can be registered with the Lua function \fIcore.register_fetches()\fP\&. Each declared sample\-fetch is prefixed by the string "lua.". .sp \fBNOTE\fP: It is possible that this function cannot found the required data in the original HAProxy sample\-fetches, in this case, it cannot return the result. This case is not yet supported .IP 6. 3 The \fBconverter context\fP\&. It is a Lua function that takes a string as input and returns another string as output. These types of function are stateless, it cannot access to any context. They don\(aqt execute any blocking function. The call prototype is \fIfunction string fcn(string)\fP\&. This function can be registered with the Lua function \fIcore.register_converters()\fP\&. Each declared converter is prefixed by the string "lua.". .UNINDENT .SH HAPROXY LUA HELLO WORLD .sp HAProxy configuration file (\fIhello_world.conf\fP): .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C global lua\-load hello_world.lua listen proxy bind 127.0.0.1:10001 tcp\-request inspect\-delay 1s tcp\-request content use\-service lua.hello_world .ft P .fi .UNINDENT .UNINDENT .sp HAProxy Lua file (\fIhello_world.lua\fP): .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C core.register_service("hello_world", "tcp", function(applet) applet:send("hello world\en") end) .ft P .fi .UNINDENT .UNINDENT .sp How to start HAProxy for testing this configuration: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C \&./haproxy \-f hello_world.conf .ft P .fi .UNINDENT .UNINDENT .sp On other terminal, you can test with telnet: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C #:~ telnet 127.0.0.1 10001 hello world .ft P .fi .UNINDENT .UNINDENT .INDENT 0.0 .TP .B class core() The "core" class contains all the HAProxy core functions. These function are useful for the controlling the execution flow, registering hooks, manipulating global maps or ACL, ... .sp "core" class is basically provided with HAProxy. No \fIrequire\fP line is required to uses these function. .sp The "core" class is static, it is not possible to create a new object of this type. .UNINDENT .INDENT 0.0 .TP .B core.emerg .INDENT 7.0 .TP .B Returns integer .UNINDENT .sp This attribute is an integer, it contains the value of the loglevel "emergency" (0). .UNINDENT .INDENT 0.0 .TP .B core.alert .INDENT 7.0 .TP .B Returns integer .UNINDENT .sp This attribute is an integer, it contains the value of the loglevel "alert" (1). .UNINDENT .INDENT 0.0 .TP .B core.crit .INDENT 7.0 .TP .B Returns integer .UNINDENT .sp This attribute is an integer, it contains the value of the loglevel "critical" (2). .UNINDENT .INDENT 0.0 .TP .B core.err .INDENT 7.0 .TP .B Returns integer .UNINDENT .sp This attribute is an integer, it contains the value of the loglevel "error" (3). .UNINDENT .INDENT 0.0 .TP .B core.warning .INDENT 7.0 .TP .B Returns integer .UNINDENT .sp This attribute is an integer, it contains the value of the loglevel "warning" (4). .UNINDENT .INDENT 0.0 .TP .B core.notice .INDENT 7.0 .TP .B Returns integer .UNINDENT .sp This attribute is an integer, it contains the value of the loglevel "notice" (5). .UNINDENT .INDENT 0.0 .TP .B core.info .INDENT 7.0 .TP .B Returns integer .UNINDENT .sp This attribute is an integer, it contains the value of the loglevel "info" (6). .UNINDENT .INDENT 0.0 .TP .B core.debug .INDENT 7.0 .TP .B Returns integer .UNINDENT .sp This attribute is an integer, it contains the value of the loglevel "debug" (7). .UNINDENT .INDENT 0.0 .TP .B core.proxies \fBcontext\fP: task, action, sample\-fetch, converter .sp This attribute is a table of declared proxies (frontend and backends). Each proxy give an access to his list of listeners and servers. The table is indexed by proxy name, and each entry is of type \fI\%Proxy class\fP\&. .sp Warning, if you are declared frontend and backend with the same name, only one of these are listed. .INDENT 7.0 .TP .B See \fI\%core.backends\fP .TP .B See \fI\%core.frontends\fP .UNINDENT .UNINDENT .INDENT 0.0 .TP .B core.backends \fBcontext\fP: task, action, sample\-fetch, converter .sp This attribute is a table of declared proxies with backend capability. Each proxy give an access to his list of listeners and servers. The table is indexed by the backend name, and each entry is of type \fI\%Proxy class\fP\&. .INDENT 7.0 .TP .B See \fI\%core.proxies\fP .TP .B See \fI\%core.frontends\fP .UNINDENT .UNINDENT .INDENT 0.0 .TP .B core.frontends \fBcontext\fP: task, action, sample\-fetch, converter .sp This attribute is a table of declared proxies with frontend capability. Each proxy give an access to his list of listeners and servers. The table is indexed by the frontend name, and each entry is of type \fI\%Proxy class\fP\&. .INDENT 7.0 .TP .B See \fI\%core.proxies\fP .TP .B See \fI\%core.backends\fP .UNINDENT .UNINDENT .INDENT 0.0 .TP .B core.log(loglevel, msg) \fBcontext\fP: body, init, task, action, sample\-fetch, converter .sp This function sends a log. The log is sent, according with the HAProxy configuration file, on the default syslog server if it is configured and on the stderr if it is allowed. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBloglevel\fP (\fIinteger\fP) \-\- Is the log level associated with the message. It is a number between 0 and 7. .IP \(bu 2 \fBmsg\fP (\fIstring\fP) \-\- The log content. .UNINDENT .TP .B See \fI\%core.emerg\fP, \fI\%core.alert\fP, \fI\%core.crit\fP, \fI\%core.err\fP, \fI\%core.warning\fP, \fI\%core.notice\fP, \fI\%core.info\fP, \fI\%core.debug\fP (log level definitions) .TP .B See \fI\%core.Debug()\fP .TP .B See \fI\%core.Info()\fP .TP .B See \fI\%core.Warning()\fP .TP .B See \fI\%core.Alert()\fP .UNINDENT .UNINDENT .INDENT 0.0 .TP .B core.Debug(msg) \fBcontext\fP: body, init, task, action, sample\-fetch, converter .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBmsg\fP (\fIstring\fP) \-\- The log content. .UNINDENT .TP .B See \fI\%core.log()\fP .UNINDENT .sp Does the same job than: .UNINDENT .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C function Debug(msg) core.log(core.debug, msg) end .ft P .fi .UNINDENT .UNINDENT .INDENT 0.0 .TP .B core.Info(msg) \fBcontext\fP: body, init, task, action, sample\-fetch, converter .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBmsg\fP (\fIstring\fP) \-\- The log content. .UNINDENT .TP .B See \fI\%core.log()\fP .UNINDENT .UNINDENT .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C function Info(msg) core.log(core.info, msg) end .ft P .fi .UNINDENT .UNINDENT .INDENT 0.0 .TP .B core.Warning(msg) \fBcontext\fP: body, init, task, action, sample\-fetch, converter .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBmsg\fP (\fIstring\fP) \-\- The log content. .UNINDENT .TP .B See \fI\%core.log()\fP .UNINDENT .UNINDENT .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C function Warning(msg) core.log(core.warning, msg) end .ft P .fi .UNINDENT .UNINDENT .INDENT 0.0 .TP .B core.Alert(msg) \fBcontext\fP: body, init, task, action, sample\-fetch, converter .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBmsg\fP (\fIstring\fP) \-\- The log content. .UNINDENT .TP .B See \fI\%core.log()\fP .UNINDENT .UNINDENT .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C function Alert(msg) core.log(core.alert, msg) end .ft P .fi .UNINDENT .UNINDENT .INDENT 0.0 .TP .B core.add_acl(filename, key) \fBcontext\fP: init, task, action, sample\-fetch, converter .sp Add the ACL \fIkey\fP in the ACLs list referenced by the file \fIfilename\fP\&. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBfilename\fP (\fIstring\fP) \-\- the filename that reference the ACL entries. .IP \(bu 2 \fBkey\fP (\fIstring\fP) \-\- the key which will be added. .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B core.del_acl(filename, key) \fBcontext\fP: init, task, action, sample\-fetch, converter .sp Delete the ACL entry referenced by the key \fIkey\fP in the list of ACLs referenced by \fIfilename\fP\&. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBfilename\fP (\fIstring\fP) \-\- the filename that reference the ACL entries. .IP \(bu 2 \fBkey\fP (\fIstring\fP) \-\- the key which will be deleted. .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B core.del_map(filename, key) \fBcontext\fP: init, task, action, sample\-fetch, converter .sp Delete the map entry indexed with the specified key in the list of maps referenced by his filename. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBfilename\fP (\fIstring\fP) \-\- the filename that reference the map entries. .IP \(bu 2 \fBkey\fP (\fIstring\fP) \-\- the key which will be deleted. .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B core.get_info() \fBcontext\fP: body, init, task, action, sample\-fetch, converter .sp Returns HAProxy core information. We can found information like the uptime, the pid, memory pool usage, tasks number, ... .sp These information are also returned by the management socket via the command "show info". See the management socket documentation for more information about the content of these variables. .INDENT 7.0 .TP .B Returns an array of values. .UNINDENT .UNINDENT .INDENT 0.0 .TP .B core.now() \fBcontext\fP: body, init, task, action .sp This function returns the current time. The time returned is fixed by the HAProxy core and assures than the hour will be monotonic and that the system call \(aqgettimeofday\(aq will not be called too. The time is refreshed between each Lua execution or resume, so two consecutive call to the function "now" will probably returns the same result. .INDENT 7.0 .TP .B Returns a table which contains two entries "sec" and "usec". "sec" contains the current at the epoch format, and "usec" contains the current microseconds. .UNINDENT .UNINDENT .INDENT 0.0 .TP .B core.http_date(date) \fBcontext\fP: body, init, task, action .sp This function take a string representing http date, and returns an integer containing the corresponding date with a epoch format. A valid http date me respect the format IMF, RFC850 or ASCTIME. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBdate\fP (\fIstring\fP) \-\- a date http\-date formatted .UNINDENT .TP .B Returns integer containing epoch date .TP .B See \fI\%core.imf_date()\fP\&. .TP .B See \fI\%core.rfc850_date()\fP\&. .TP .B See \fI\%core.asctime_date()\fP\&. .TP .B See \fI\%https://tools.ietf.org/html/rfc7231#section\-7.1.1.1\fP .UNINDENT .UNINDENT .INDENT 0.0 .TP .B core.imf_date(date) \fBcontext\fP: body, init, task, action .sp This function take a string representing IMF date, and returns an integer containing the corresponding date with a epoch format. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBdate\fP (\fIstring\fP) \-\- a date IMF formatted .UNINDENT .TP .B Returns integer containing epoch date .TP .B See \fI\%https://tools.ietf.org/html/rfc7231#section\-7.1.1.1\fP .UNINDENT .sp The IMF format is like this: .UNINDENT .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C Sun, 06 Nov 1994 08:49:37 GMT .ft P .fi .UNINDENT .UNINDENT .INDENT 0.0 .TP .B core.rfc850_date(date) \fBcontext\fP: body, init, task, action .sp This function take a string representing RFC850 date, and returns an integer containing the corresponding date with a epoch format. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBdate\fP (\fIstring\fP) \-\- a date RFC859 formatted .UNINDENT .TP .B Returns integer containing epoch date .TP .B See \fI\%https://tools.ietf.org/html/rfc7231#section\-7.1.1.1\fP .UNINDENT .sp The RFC850 format is like this: .UNINDENT .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C Sunday, 06\-Nov\-94 08:49:37 GMT .ft P .fi .UNINDENT .UNINDENT .INDENT 0.0 .TP .B core.asctime_date(date) \fBcontext\fP: body, init, task, action .sp This function take a string representing ASCTIME date, and returns an integer containing the corresponding date with a epoch format. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBdate\fP (\fIstring\fP) \-\- a date ASCTIME formatted .UNINDENT .TP .B Returns integer containing epoch date .TP .B See \fI\%https://tools.ietf.org/html/rfc7231#section\-7.1.1.1\fP .UNINDENT .sp The ASCTIME format is like this: .UNINDENT .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C Sun Nov 6 08:49:37 1994 .ft P .fi .UNINDENT .UNINDENT .INDENT 0.0 .TP .B core.rfc850_date(date) \fBcontext\fP: body, init, task, action .sp This function take a string representing http date, and returns an integer containing the corresponding date with a epoch format. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBdate\fP (\fIstring\fP) \-\- a date http\-date formatted .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B core.asctime_date(date) \fBcontext\fP: body, init, task, action .sp This function take a string representing http date, and returns an integer containing the corresponding date with a epoch format. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBdate\fP (\fIstring\fP) \-\- a date http\-date formatted .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B core.msleep(milliseconds) \fBcontext\fP: body, init, task, action .sp The \fIcore.msleep()\fP stops the Lua execution between specified milliseconds. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBmilliseconds\fP (\fIinteger\fP) \-\- the required milliseconds. .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B core.proxies \fBcontext\fP: body, init, task, action, sample\-fetch, converter .sp Proxies is a table containing the list of all proxies declared in the configuration file. The table is indexed by the proxy name, and each entry of the proxies table is an object of type \fI\%Proxy class\fP\&. .sp Warning, if you have declared a frontend and backend with the same name, only one of these are listed. .UNINDENT .INDENT 0.0 .TP .B core.register_action(name, actions, func[, nb_args]) \fBcontext\fP: body .sp Register a Lua function executed as action. All the registered action can be used in HAProxy with the prefix "lua.". An action gets a TXN object class as input. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBname\fP (\fIstring\fP) \-\- is the name of the converter. .IP \(bu 2 \fBactions\fP (\fItable\fP) \-\- is a table of string describing the HAProxy actions who want to register to. The expected actions are \(aqtcp\-req\(aq, \(aqtcp\-res\(aq, \(aqhttp\-req\(aq or \(aqhttp\-res\(aq. .IP \(bu 2 \fBnb_args\fP (\fIinteger\fP) \-\- is the expected number of argument for the action. By default the value is 0. .IP \(bu 2 \fBfunc\fP (\fIfunction\fP) \-\- is the Lua function called to work as converter. .UNINDENT .UNINDENT .sp The prototype of the Lua function used as argument is: .UNINDENT .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C function(txn [, arg1 [, arg2]]) .ft P .fi .UNINDENT .UNINDENT .INDENT 0.0 .INDENT 3.5 .INDENT 0.0 .IP \(bu 2 .INDENT 2.0 .TP \fBtxn\fP (\fI\%TXN class\fP): this is a TXN object used for manipulating the current request or TCP stream. .UNINDENT .IP \(bu 2 \fBargX\fP: this is argument provided through the HAProxy configuration file. .UNINDENT .sp Here, an example of action registration. The action just send an \(aqHello world\(aq in the logs. .UNINDENT .UNINDENT .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C core.register_action("hello\-world", { "tcp\-req", "http\-req" }, function(txn) txn:Info("Hello world") end) .ft P .fi .UNINDENT .UNINDENT .INDENT 0.0 .INDENT 3.5 This example code is used in HAproxy configuration like this: .UNINDENT .UNINDENT .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C frontend tcp_frt mode tcp tcp\-request content lua.hello\-world frontend http_frt mode http http\-request lua.hello\-world .ft P .fi .UNINDENT .UNINDENT .INDENT 0.0 .INDENT 3.5 A second example using arguments .UNINDENT .UNINDENT .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C function hello_world(txn, arg) txn:Info("Hello world for " .. arg) end core.register_action("hello\-world", { "tcp\-req", "http\-req" }, hello_world, 2) .ft P .fi .UNINDENT .UNINDENT .INDENT 0.0 .INDENT 3.5 This example code is used in HAproxy configuration like this: .UNINDENT .UNINDENT .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C frontend tcp_frt mode tcp tcp\-request content lua.hello\-world everybody .ft P .fi .UNINDENT .UNINDENT .INDENT 0.0 .TP .B core.register_converters(name, func) \fBcontext\fP: body .sp Register a Lua function executed as converter. All the registered converters can be used in HAProxy with the prefix "lua.". An converter get a string as input and return a string as output. The registered function can take up to 9 values as parameter. All the value are strings. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBname\fP (\fIstring\fP) \-\- is the name of the converter. .IP \(bu 2 \fBfunc\fP (\fIfunction\fP) \-\- is the Lua function called to work as converter. .UNINDENT .UNINDENT .sp The prototype of the Lua function used as argument is: .UNINDENT .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C function(str, [p1 [, p2 [, ... [, p5]]]]) .ft P .fi .UNINDENT .UNINDENT .INDENT 0.0 .INDENT 3.5 .INDENT 0.0 .IP \(bu 2 \fBstr\fP (\fIstring\fP): this is the input value automatically converted in string. .IP \(bu 2 \fBp1\fP .. \fBp5\fP (\fIstring\fP): this is a list of string arguments declared in the HAProxy configuration file. The number of arguments doesn\(aqt exceed 5. The order and the nature of these is conventionally choose by the developer. .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B core.register_fetches(name, func) \fBcontext\fP: body .sp Register a Lua function executed as sample fetch. All the registered sample fetch can be used in HAProxy with the prefix "lua.". A Lua sample fetch return a string as output. The registered function can take up to 9 values as parameter. All the value are strings. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBname\fP (\fIstring\fP) \-\- is the name of the converter. .IP \(bu 2 \fBfunc\fP (\fIfunction\fP) \-\- is the Lua function called to work as sample fetch. .UNINDENT .UNINDENT .sp The prototype of the Lua function used as argument is: .UNINDENT .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C string function(txn, [p1 [, p2 [, ... [, p5]]]]) .ft P .fi .UNINDENT .UNINDENT .INDENT 0.0 .INDENT 3.5 .INDENT 0.0 .IP \(bu 2 \fBtxn\fP (\fI\%TXN class\fP): this is the txn object associated with the current request. .IP \(bu 2 \fBp1\fP .. \fBp5\fP (\fIstring\fP): this is a list of string arguments declared in the HAProxy configuration file. The number of arguments doesn\(aqt exceed 5. The order and the nature of these is conventionally choose by the developer. .IP \(bu 2 \fBReturns\fP: A string containing some data, or nil if the value cannot be returned now. .UNINDENT .sp lua example code: .UNINDENT .UNINDENT .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C core.register_fetches("hello", function(txn) return "hello" end) .ft P .fi .UNINDENT .UNINDENT .INDENT 0.0 .INDENT 3.5 HAProxy example configuration: .UNINDENT .UNINDENT .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C frontend example http\-request redirect location /%[lua.hello] .ft P .fi .UNINDENT .UNINDENT .INDENT 0.0 .TP .B core.register_service(name, mode, func) \fBcontext\fP: body .sp Register a Lua function executed as a service. All the registered service can be used in HAProxy with the prefix "lua.". A service gets an object class as input according with the required mode. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBname\fP (\fIstring\fP) \-\- is the name of the converter. .IP \(bu 2 \fBmode\fP (\fIstring\fP) \-\- is string describing the required mode. Only \(aqtcp\(aq or \(aqhttp\(aq are allowed. .IP \(bu 2 \fBfunc\fP (\fIfunction\fP) \-\- is the Lua function called to work as converter. .UNINDENT .UNINDENT .sp The prototype of the Lua function used as argument is: .UNINDENT .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C function(applet) .ft P .fi .UNINDENT .UNINDENT .INDENT 0.0 .INDENT 3.5 .INDENT 0.0 .IP \(bu 2 \fBapplet\fP \fIapplet\fP will be a \fI\%AppletTCP class\fP or a \fI\%AppletHTTP class\fP\&. It depends the type of registered applet. An applet registered with the \(aqhttp\(aq value for the \fImode\fP parameter will gets a \fI\%AppletHTTP class\fP\&. If the \fImode\fP value is \(aqtcp\(aq, the applet will gets a \fI\%AppletTCP class\fP\&. .UNINDENT .sp \fBwarning\fP: Applets of type \(aqhttp\(aq cannot be called from \(aqtcp\-\fI\(aq rulesets. Only the \(aqhttp\-\fP\(aq rulesets are authorized, this means that is not possible to call an HTTP applet from a proxy in tcp mode. Applets of type \(aqtcp\(aq can be called from anywhere. .sp Here, an example of service registration. The service just send an \(aqHello world\(aq as an http response. .UNINDENT .UNINDENT .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C core.register_service("hello\-world", "http", function(applet) local response = "Hello World !" applet:set_status(200) applet:add_header("content\-length", string.len(response)) applet:add_header("content\-type", "text/plain") applet:start_response() applet:send(response) end) .ft P .fi .UNINDENT .UNINDENT .INDENT 0.0 .INDENT 3.5 This example code is used in HAproxy configuration like this: .UNINDENT .UNINDENT .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C frontend example http\-request use\-service lua.hello\-world .ft P .fi .UNINDENT .UNINDENT .INDENT 0.0 .TP .B core.register_init(func) \fBcontext\fP: body .sp Register a function executed after the configuration parsing. This is useful to check any parameters. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBfunc\fP (\fIfunction\fP) \-\- is the Lua function called to work as initializer. .UNINDENT .UNINDENT .sp The prototype of the Lua function used as argument is: .UNINDENT .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C function() .ft P .fi .UNINDENT .UNINDENT .INDENT 0.0 .INDENT 3.5 It takes no input, and no output is expected. .UNINDENT .UNINDENT .INDENT 0.0 .TP .B core.register_task(func) \fBcontext\fP: body, init, task, action, sample\-fetch, converter .sp Register and start independent task. The task is started when the HAProxy main scheduler starts. For example this type of tasks can be executed to perform complex health checks. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBfunc\fP (\fIfunction\fP) \-\- is the Lua function called to work as initializer. .UNINDENT .UNINDENT .sp The prototype of the Lua function used as argument is: .UNINDENT .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C function() .ft P .fi .UNINDENT .UNINDENT .INDENT 0.0 .INDENT 3.5 It takes no input, and no output is expected. .UNINDENT .UNINDENT .INDENT 0.0 .TP .B core.register_cli([path], usage, func) \fBcontext\fP: body .sp Register and start independent task. The task is started when the HAProxy main scheduler starts. For example this type of tasks can be executed to perform complex health checks. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBpath\fP (\fIarray\fP) \-\- is the sequence of word for which the cli execute the Lua binding. .IP \(bu 2 \fBusage\fP (\fIstring\fP) \-\- is the usage message displayed in the help. .IP \(bu 2 \fBfunc\fP (\fIfunction\fP) \-\- is the Lua function called to handle the CLI commands. .UNINDENT .UNINDENT .sp The prototype of the Lua function used as argument is: .UNINDENT .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C function(AppletTCP, [arg1, [arg2, [...]]]) .ft P .fi .UNINDENT .UNINDENT .INDENT 0.0 .INDENT 3.5 I/O are managed with the \fI\%AppletTCP class\fP object. Args are given as parameter. The args embed the registered path. If the path is declared like this: .UNINDENT .UNINDENT .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C core.register_cli({"show", "ssl", "stats"}, "Display SSL stats..", function(applet, arg1, arg2, arg3, arg4, arg5) end) .ft P .fi .UNINDENT .UNINDENT .INDENT 0.0 .INDENT 3.5 And we execute this in the prompt: .UNINDENT .UNINDENT .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C > prompt > show ssl stats all .ft P .fi .UNINDENT .UNINDENT .INDENT 0.0 .INDENT 3.5 Then, arg1, arg2 and arg3 will contains respectively "show", "ssl" and "stats". arg4 will contain "all". arg5 contains nil. .UNINDENT .UNINDENT .INDENT 0.0 .TP .B core.set_nice(nice) \fBcontext\fP: task, action, sample\-fetch, converter .sp Change the nice of the current task or current session. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBnice\fP (\fIinteger\fP) \-\- the nice value, it must be between \-1024 and 1024. .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B core.set_map(filename, key, value) \fBcontext\fP: init, task, action, sample\-fetch, converter .sp Set the value \fIvalue\fP associated to the key \fIkey\fP in the map referenced by \fIfilename\fP\&. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBfilename\fP (\fIstring\fP) \-\- the Map reference .IP \(bu 2 \fBkey\fP (\fIstring\fP) \-\- the key to set or replace .IP \(bu 2 \fBvalue\fP (\fIstring\fP) \-\- the associated value .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B core.sleep(int seconds) \fBcontext\fP: body, init, task, action .sp The \fIcore.sleep()\fP functions stop the Lua execution between specified seconds. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBseconds\fP (\fIinteger\fP) \-\- the required seconds. .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B core.tcp() \fBcontext\fP: init, task, action .sp This function returns a new object of a \fIsocket\fP class. .INDENT 7.0 .TP .B Returns A \fI\%Socket class\fP object. .UNINDENT .UNINDENT .INDENT 0.0 .TP .B core.concat() \fBcontext\fP: body, init, task, action, sample\-fetch, converter .sp This function returns a new concat object. .INDENT 7.0 .TP .B Returns A \fI\%Concat class\fP object. .UNINDENT .UNINDENT .INDENT 0.0 .TP .B core.done(data) \fBcontext\fP: body, init, task, action, sample\-fetch, converter .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBdata\fP (\fIany\fP) \-\- Return some data for the caller. It is useful with sample\-fetches and sample\-converters. .UNINDENT .UNINDENT .sp Immediately stops the current Lua execution and returns to the caller which may be a sample fetch, a converter or an action and returns the specified value (ignored for actions). It is used when the LUA process finishes its work and wants to give back the control to HAProxy without executing the remaining code. It can be seen as a multi\-level "return". .UNINDENT .INDENT 0.0 .TP .B core.yield() \fBcontext\fP: task, action, sample\-fetch, converter .sp Give back the hand at the HAProxy scheduler. It is used when the LUA processing consumes a lot of processing time. .UNINDENT .INDENT 0.0 .TP .B core.parse_addr(address) \fBcontext\fP: body, init, task, action, sample\-fetch, converter .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBnetwork\fP \-\- is a string describing an ipv4 or ipv6 address and optionally its network length, like this: "127.0.0.1/8" or "aaaa::1234/32". .UNINDENT .TP .B Returns a userdata containing network or nil if an error occurs. .UNINDENT .sp Parse ipv4 or ipv6 addresses and its facultative associated network. .UNINDENT .INDENT 0.0 .TP .B core.match_addr(addr1, addr2) \fBcontext\fP: body, init, task, action, sample\-fetch, converter .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBaddr1\fP \-\- is an address created with "core.parse_addr". .IP \(bu 2 \fBaddr2\fP \-\- is an address created with "core.parse_addr". .UNINDENT .TP .B Returns boolean, true if the network of the addresses match, else returns false. .UNINDENT .sp Match two networks. For example "127.0.0.1/32" matches "127.0.0.0/8". The order of network is not important. .UNINDENT .INDENT 0.0 .TP .B core.tokenize(str, separators[, noblank]) \fBcontext\fP: body, init, task, action, sample\-fetch, converter .sp This function is useful for tokenizing an entry, or splitting some messages. :param string str: The string which will be split. :param string separators: A string containing a list of separators. :param boolean noblank: Ignore empty entries. :returns: an array of string. .sp For example: .UNINDENT .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C local array = core.tokenize("This function is useful, for tokenizing an entry.", "., ", true) print_r(array) .ft P .fi .UNINDENT .UNINDENT .INDENT 0.0 .INDENT 3.5 Returns this array: .UNINDENT .UNINDENT .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C (table) table: 0x21c01e0 [ 1: (string) "This" 2: (string) "function" 3: (string) "is" 4: (string) "useful" 5: (string) "for" 6: (string) "tokenizing" 7: (string) "an" 8: (string) "entry" ] .ft P .fi .UNINDENT .UNINDENT .INDENT 0.0 .TP .B class Proxy() This class provides a way for manipulating proxy and retrieving information like statistics. .UNINDENT .INDENT 0.0 .TP .B Proxy.name Contain the name of the proxy. .UNINDENT .INDENT 0.0 .TP .B Proxy.uuid Contain the unique identifier of the proxy. .UNINDENT .INDENT 0.0 .TP .B Proxy.servers Contain a table with the attached servers. The table is indexed by server name, and each server entry is an object of type \fI\%Server class\fP\&. .UNINDENT .INDENT 0.0 .TP .B Proxy.stktable Contains a stick table object attached to the proxy. .UNINDENT .INDENT 0.0 .TP .B Proxy.listeners Contain a table with the attached listeners. The table is indexed by listener name, and each each listeners entry is an object of type \fI\%Listener class\fP\&. .UNINDENT .INDENT 0.0 .TP .B Proxy.pause(px) Pause the proxy. See the management socket documentation for more information. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBpx\fP (\fIclass_proxy\fP) \-\- A \fI\%Proxy class\fP which indicates the manipulated proxy. .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B Proxy.resume(px) Resume the proxy. See the management socket documentation for more information. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBpx\fP (\fIclass_proxy\fP) \-\- A \fI\%Proxy class\fP which indicates the manipulated proxy. .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B Proxy.stop(px) Stop the proxy. See the management socket documentation for more information. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBpx\fP (\fIclass_proxy\fP) \-\- A \fI\%Proxy class\fP which indicates the manipulated proxy. .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B Proxy.shut_bcksess(px) Kill the session attached to a backup server. See the management socket documentation for more information. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBpx\fP (\fIclass_proxy\fP) \-\- A \fI\%Proxy class\fP which indicates the manipulated proxy. .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B Proxy.get_cap(px) Returns a string describing the capabilities of the proxy. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBpx\fP (\fIclass_proxy\fP) \-\- A \fI\%Proxy class\fP which indicates the manipulated proxy. .UNINDENT .TP .B Returns a string "frontend", "backend", "proxy" or "ruleset". .UNINDENT .UNINDENT .INDENT 0.0 .TP .B Proxy.get_mode(px) Returns a string describing the mode of the current proxy. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBpx\fP (\fIclass_proxy\fP) \-\- A \fI\%Proxy class\fP which indicates the manipulated proxy. .UNINDENT .TP .B Returns a string "tcp", "http", "health" or "unknown" .UNINDENT .UNINDENT .INDENT 0.0 .TP .B Proxy.get_stats(px) Returns a table containing the proxy statistics. The statistics returned are not the same if the proxy is frontend or a backend. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBpx\fP (\fIclass_proxy\fP) \-\- A \fI\%Proxy class\fP which indicates the manipulated proxy. .UNINDENT .TP .B Returns a key/value table containing stats .UNINDENT .UNINDENT .INDENT 0.0 .TP .B class Server() This class provides a way for manipulating servers and retrieving information. .UNINDENT .INDENT 0.0 .TP .B Server.name Contain the name of the server. .UNINDENT .INDENT 0.0 .TP .B Server.puid Contain the proxy unique identifier of the server. .UNINDENT .INDENT 0.0 .TP .B Server.is_draining(sv) Return true if the server is currently draining sticky connections. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBsv\fP (\fIclass_server\fP) \-\- A \fI\%Server class\fP which indicates the manipulated server. .UNINDENT .TP .B Returns a boolean .UNINDENT .UNINDENT .INDENT 0.0 .TP .B Server.set_maxconn(sv, weight) Dynamically change the maximum connections of the server. See the management socket documentation for more information about the format of the string. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBsv\fP (\fIclass_server\fP) \-\- A \fI\%Server class\fP which indicates the manipulated server. .IP \(bu 2 \fBmaxconn\fP (\fIstring\fP) \-\- A string describing the server maximum connections. .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B Server.get_maxconn(sv, weight) This function returns an integer representing the server maximum connections. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBsv\fP (\fIclass_server\fP) \-\- A \fI\%Server class\fP which indicates the manipulated server. .UNINDENT .TP .B Returns an integer. .UNINDENT .UNINDENT .INDENT 0.0 .TP .B Server.set_weight(sv, weight) Dynamically change the weight of the server. See the management socket documentation for more information about the format of the string. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBsv\fP (\fIclass_server\fP) \-\- A \fI\%Server class\fP which indicates the manipulated server. .IP \(bu 2 \fBweight\fP (\fIstring\fP) \-\- A string describing the server weight. .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B Server.get_weight(sv) This function returns an integer representing the server weight. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBsv\fP (\fIclass_server\fP) \-\- A \fI\%Server class\fP which indicates the manipulated server. .UNINDENT .TP .B Returns an integer. .UNINDENT .UNINDENT .INDENT 0.0 .TP .B Server.set_addr(sv, addr[, port]) Dynamically change the address of the server. See the management socket documentation for more information about the format of the string. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBsv\fP (\fIclass_server\fP) \-\- A \fI\%Server class\fP which indicates the manipulated server. .IP \(bu 2 \fBaddr\fP (\fIstring\fP) \-\- A string describing the server address. .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B Server.get_addr(sv) Returns a string describing the address of the server. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBsv\fP (\fIclass_server\fP) \-\- A \fI\%Server class\fP which indicates the manipulated server. .UNINDENT .TP .B Returns A string .UNINDENT .UNINDENT .INDENT 0.0 .TP .B Server.get_stats(sv) Returns server statistics. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBsv\fP (\fIclass_server\fP) \-\- A \fI\%Server class\fP which indicates the manipulated server. .UNINDENT .TP .B Returns a key/value table containing stats .UNINDENT .UNINDENT .INDENT 0.0 .TP .B Server.shut_sess(sv) Shutdown all the sessions attached to the server. See the management socket documentation for more information about this function. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBsv\fP (\fIclass_server\fP) \-\- A \fI\%Server class\fP which indicates the manipulated server. .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B Server.set_drain(sv) Drain sticky sessions. See the management socket documentation for more information about this function. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBsv\fP (\fIclass_server\fP) \-\- A \fI\%Server class\fP which indicates the manipulated server. .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B Server.set_maint(sv) Set maintenance mode. See the management socket documentation for more information about this function. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBsv\fP (\fIclass_server\fP) \-\- A \fI\%Server class\fP which indicates the manipulated server. .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B Server.set_ready(sv) Set normal mode. See the management socket documentation for more information about this function. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBsv\fP (\fIclass_server\fP) \-\- A \fI\%Server class\fP which indicates the manipulated server. .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B Server.check_enable(sv) Enable health checks. See the management socket documentation for more information about this function. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBsv\fP (\fIclass_server\fP) \-\- A \fI\%Server class\fP which indicates the manipulated server. .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B Server.check_disable(sv) Disable health checks. See the management socket documentation for more information about this function. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBsv\fP (\fIclass_server\fP) \-\- A \fI\%Server class\fP which indicates the manipulated server. .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B Server.check_force_up(sv) Force health\-check up. See the management socket documentation for more information about this function. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBsv\fP (\fIclass_server\fP) \-\- A \fI\%Server class\fP which indicates the manipulated server. .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B Server.check_force_nolb(sv) Force health\-check nolb mode. See the management socket documentation for more information about this function. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBsv\fP (\fIclass_server\fP) \-\- A \fI\%Server class\fP which indicates the manipulated server. .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B Server.check_force_down(sv) Force health\-check down. See the management socket documentation for more information about this function. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBsv\fP (\fIclass_server\fP) \-\- A \fI\%Server class\fP which indicates the manipulated server. .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B Server.agent_enable(sv) Enable agent check. See the management socket documentation for more information about this function. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBsv\fP (\fIclass_server\fP) \-\- A \fI\%Server class\fP which indicates the manipulated server. .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B Server.agent_disable(sv) Disable agent check. See the management socket documentation for more information about this function. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBsv\fP (\fIclass_server\fP) \-\- A \fI\%Server class\fP which indicates the manipulated server. .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B Server.agent_force_up(sv) Force agent check up. See the management socket documentation for more information about this function. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBsv\fP (\fIclass_server\fP) \-\- A \fI\%Server class\fP which indicates the manipulated server. .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B Server.agent_force_down(sv) Force agent check down. See the management socket documentation for more information about this function. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBsv\fP (\fIclass_server\fP) \-\- A \fI\%Server class\fP which indicates the manipulated server. .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B Listener.get_stats(ls) Returns server statistics. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBls\fP (\fIclass_listener\fP) \-\- A \fI\%Listener class\fP which indicates the manipulated listener. .UNINDENT .TP .B Returns a key/value table containing stats .UNINDENT .UNINDENT .INDENT 0.0 .TP .B class Concat() This class provides a fast way for string concatenation. The way using native Lua concatenation like the code below is slow for some reasons. .UNINDENT .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C str = "string1" str = str .. ", string2" str = str .. ", string3" .ft P .fi .UNINDENT .UNINDENT .INDENT 0.0 .INDENT 3.5 For each concatenation, Lua: * allocate memory for the result, * catenate the two string copying the strings in the new memory block, * free the old memory block containing the string which is no longer used. This process does many memory move, allocation and free. In addition, the memory is not really freed, it is just mark mark as unused and wait for the garbage collector. .sp The Concat class provide an alternative way to concatenate strings. It uses the internal Lua mechanism (it does not allocate memory), but it doesn\(aqt copy the data more than once. .sp On my computer, the following loops spends 0.2s for the Concat method and 18.5s for the pure Lua implementation. So, the Concat class is about 1000x faster than the embedded solution. .UNINDENT .UNINDENT .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C for j = 1, 100 do c = core.concat() for i = 1, 20000 do c:add("#####") end end .ft P .fi .UNINDENT .UNINDENT .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C for j = 1, 100 do c = "" for i = 1, 20000 do c = c .. "#####" end end .ft P .fi .UNINDENT .UNINDENT .INDENT 0.0 .TP .B Concat.add(concat, string) This function adds a string to the current concatenated string. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBconcat\fP (\fIclass_concat\fP) \-\- A \fI\%Concat class\fP which contains the currently built string. .IP \(bu 2 \fBstring\fP (\fIstring\fP) \-\- A new string to concatenate to the current built string. .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B Concat.dump(concat) This function returns the concatenated string. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBconcat\fP (\fIclass_concat\fP) \-\- A \fI\%Concat class\fP which contains the currently built string. .UNINDENT .TP .B Returns the concatenated string .UNINDENT .UNINDENT .INDENT 0.0 .TP .B class Fetches() This class contains a lot of internal HAProxy sample fetches. See the HAProxy "configuration.txt" documentation for more information about her usage. They are the chapters 7.3.2 to 7.3.6. .sp \fBwarning\fP some sample fetches are not available in some context. These limitations are specified in this documentation when they\(aqre useful. .INDENT 7.0 .TP .B See \fI\%TXN.f\fP .TP .B See \fI\%TXN.sf\fP .UNINDENT .sp Fetches are useful for: .INDENT 7.0 .IP \(bu 2 get system time, .IP \(bu 2 get environment variable, .IP \(bu 2 get random numbers, .IP \(bu 2 known backend status like the number of users in queue or the number of connections established, .IP \(bu 2 client information like ip source or destination, .IP \(bu 2 deal with stick tables, .IP \(bu 2 Established SSL information, .IP \(bu 2 HTTP information like headers or method. .UNINDENT .UNINDENT .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C function action(txn) \-\- Get source IP local clientip = txn.f:src() end .ft P .fi .UNINDENT .UNINDENT .INDENT 0.0 .TP .B class Converters() This class contains a lot of internal HAProxy sample converters. See the HAProxy documentation "configuration.txt" for more information about her usage. Its the chapter 7.3.1. .INDENT 7.0 .TP .B See \fI\%TXN.c\fP .TP .B See \fI\%TXN.sc\fP .UNINDENT .sp Converters provides statefull transformation. They are useful for: .INDENT 7.0 .IP \(bu 2 converting input to base64, .IP \(bu 2 applying hash on input string (djb2, crc32, sdbm, wt6), .IP \(bu 2 format date, .IP \(bu 2 json escape, .IP \(bu 2 extracting preferred language comparing two lists, .IP \(bu 2 turn to lower or upper chars, .IP \(bu 2 deal with stick tables. .UNINDENT .UNINDENT .INDENT 0.0 .TP .B class Channel() HAProxy uses two buffers for the processing of the requests. The first one is used with the request data (from the client to the server) and the second is used for the response data (from the server to the client). .sp Each buffer contains two types of data. The first type is the incoming data waiting for a processing. The second part is the outgoing data already processed. Usually, the incoming data is processed, after it is tagged as outgoing data, and finally it is sent. The following functions provides tools for manipulating these data in a buffer. .sp The following diagram shows where the channel class function are applied. .sp \fBWarning\fP: It is not possible to read from the response in request action, and it is not possible to read for the request channel in response action. .UNINDENT [image] .INDENT 0.0 .TP .B Channel.dup(channel) This function returns a string that contain the entire buffer. The data is not remove from the buffer and can be reprocessed later. .sp If the buffer can\(aqt receive more data, a \(aqnil\(aq value is returned. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBchannel\fP (\fIclass_channel\fP) \-\- The manipulated Channel. .UNINDENT .TP .B Returns a string containing all the available data or nil. .UNINDENT .UNINDENT .INDENT 0.0 .TP .B Channel.get(channel) This function returns a string that contain the entire buffer. The data is consumed from the buffer. .sp If the buffer can\(aqt receive more data, a \(aqnil\(aq value is returned. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBchannel\fP (\fIclass_channel\fP) \-\- The manipulated Channel. .UNINDENT .TP .B Returns a string containing all the available data or nil. .UNINDENT .UNINDENT .INDENT 0.0 .TP .B Channel.getline(channel) This function returns a string that contain the first line of the buffer. The data is consumed. If the data returned doesn\(aqt contains a final \(aqn\(aq its assumed than its the last available data in the buffer. .sp If the buffer can\(aqt receive more data, a \(aqnil\(aq value is returned. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBchannel\fP (\fIclass_channel\fP) \-\- The manipulated Channel. .UNINDENT .TP .B Returns a string containing the available line or nil. .UNINDENT .UNINDENT .INDENT 0.0 .TP .B Channel.set(channel, string) This function replace the content of the buffer by the string. The function returns the copied length, otherwise, it returns \-1. .sp The data set with this function are not send. They wait for the end of HAProxy processing, so the buffer can be full. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBchannel\fP (\fIclass_channel\fP) \-\- The manipulated Channel. .IP \(bu 2 \fBstring\fP (\fIstring\fP) \-\- The data which will sent. .UNINDENT .TP .B Returns an integer containing the amount of bytes copied or \-1. .UNINDENT .UNINDENT .INDENT 0.0 .TP .B Channel.append(channel, string) This function append the string argument to the content of the buffer. The function returns the copied length, otherwise, it returns \-1. .sp The data set with this function are not send. They wait for the end of HAProxy processing, so the buffer can be full. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBchannel\fP (\fIclass_channel\fP) \-\- The manipulated Channel. .IP \(bu 2 \fBstring\fP (\fIstring\fP) \-\- The data which will sent. .UNINDENT .TP .B Returns an integer containing the amount of bytes copied or \-1. .UNINDENT .UNINDENT .INDENT 0.0 .TP .B Channel.send(channel, string) This function required immediate send of the data. Unless if the connection is close, the buffer is regularly flushed and all the string can be sent. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBchannel\fP (\fIclass_channel\fP) \-\- The manipulated Channel. .IP \(bu 2 \fBstring\fP (\fIstring\fP) \-\- The data which will sent. .UNINDENT .TP .B Returns an integer containing the amount of bytes copied or \-1. .UNINDENT .UNINDENT .INDENT 0.0 .TP .B Channel.get_in_length(channel) This function returns the length of the input part of the buffer. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBchannel\fP (\fIclass_channel\fP) \-\- The manipulated Channel. .UNINDENT .TP .B Returns an integer containing the amount of available bytes. .UNINDENT .UNINDENT .INDENT 0.0 .TP .B Channel.get_out_length(channel) This function returns the length of the output part of the buffer. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBchannel\fP (\fIclass_channel\fP) \-\- The manipulated Channel. .UNINDENT .TP .B Returns an integer containing the amount of available bytes. .UNINDENT .UNINDENT .INDENT 0.0 .TP .B Channel.forward(channel, int) This function transfer bytes from the input part of the buffer to the output part. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBchannel\fP (\fIclass_channel\fP) \-\- The manipulated Channel. .IP \(bu 2 \fBint\fP (\fIinteger\fP) \-\- The amount of data which will be forwarded. .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B Channel.is_full(channel) This function returns true if the buffer channel is full. .INDENT 7.0 .TP .B Returns a boolean .UNINDENT .UNINDENT .INDENT 0.0 .TP .B class HTTP() This class contain all the HTTP manipulation functions. .UNINDENT .INDENT 0.0 .TP .B HTTP.req_get_headers(http) Returns a table containing all the request headers. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBhttp\fP (\fIclass_http\fP) \-\- The related http object. .UNINDENT .TP .B Returns table of headers. .TP .B See \fI\%HTTP.res_get_headers()\fP .UNINDENT .sp This is the form of the returned table: .UNINDENT .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C HTTP:req_get_headers()[\(aq\(aq][] = "" local hdr = HTTP:req_get_headers() hdr["host"][0] = "www.test.com" hdr["accept"][0] = "audio/basic q=1" hdr["accept"][1] = "audio/*, q=0.2" hdr["accept"][2] = "*/*, q=0.1" .ft P .fi .UNINDENT .UNINDENT .INDENT 0.0 .TP .B HTTP.res_get_headers(http) Returns a table containing all the response headers. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBhttp\fP (\fIclass_http\fP) \-\- The related http object. .UNINDENT .TP .B Returns table of headers. .TP .B See \fI\%HTTP.req_get_headers()\fP .UNINDENT .sp This is the form of the returned table: .UNINDENT .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C HTTP:res_get_headers()[\(aq\(aq][] = "" local hdr = HTTP:req_get_headers() hdr["host"][0] = "www.test.com" hdr["accept"][0] = "audio/basic q=1" hdr["accept"][1] = "audio/*, q=0.2" hdr["accept"][2] = "*.*, q=0.1" .ft P .fi .UNINDENT .UNINDENT .INDENT 0.0 .TP .B HTTP.req_add_header(http, name, value) Appends an HTTP header field in the request whose name is specified in "name" and whose value is defined in "value". .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBhttp\fP (\fIclass_http\fP) \-\- The related http object. .IP \(bu 2 \fBname\fP (\fIstring\fP) \-\- The header name. .IP \(bu 2 \fBvalue\fP (\fIstring\fP) \-\- The header value. .UNINDENT .TP .B See \fI\%HTTP.res_add_header()\fP .UNINDENT .UNINDENT .INDENT 0.0 .TP .B HTTP.res_add_header(http, name, value) Appends an HTTP header field in the response whose name is specified in "name" and whose value is defined in "value". .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBhttp\fP (\fIclass_http\fP) \-\- The related http object. .IP \(bu 2 \fBname\fP (\fIstring\fP) \-\- The header name. .IP \(bu 2 \fBvalue\fP (\fIstring\fP) \-\- The header value. .UNINDENT .TP .B See \fI\%HTTP.req_add_header()\fP .UNINDENT .UNINDENT .INDENT 0.0 .TP .B HTTP.req_del_header(http, name) Removes all HTTP header fields in the request whose name is specified in "name". .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBhttp\fP (\fIclass_http\fP) \-\- The related http object. .IP \(bu 2 \fBname\fP (\fIstring\fP) \-\- The header name. .UNINDENT .TP .B See \fI\%HTTP.res_del_header()\fP .UNINDENT .UNINDENT .INDENT 0.0 .TP .B HTTP.res_del_header(http, name) Removes all HTTP header fields in the response whose name is specified in "name". .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBhttp\fP (\fIclass_http\fP) \-\- The related http object. .IP \(bu 2 \fBname\fP (\fIstring\fP) \-\- The header name. .UNINDENT .TP .B See \fI\%HTTP.req_del_header()\fP .UNINDENT .UNINDENT .INDENT 0.0 .TP .B HTTP.req_set_header(http, name, value) This variable replace all occurrence of all header "name", by only one containing the "value". .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBhttp\fP (\fIclass_http\fP) \-\- The related http object. .IP \(bu 2 \fBname\fP (\fIstring\fP) \-\- The header name. .IP \(bu 2 \fBvalue\fP (\fIstring\fP) \-\- The header value. .UNINDENT .TP .B See \fI\%HTTP.res_set_header()\fP .UNINDENT .sp This function does the same work as the following code: .UNINDENT .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C function fcn(txn) TXN.http:req_del_header("header") TXN.http:req_add_header("header", "value") end .ft P .fi .UNINDENT .UNINDENT .INDENT 0.0 .TP .B HTTP.res_set_header(http, name, value) This variable replace all occurrence of all header "name", by only one containing the "value". .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBhttp\fP (\fIclass_http\fP) \-\- The related http object. .IP \(bu 2 \fBname\fP (\fIstring\fP) \-\- The header name. .IP \(bu 2 \fBvalue\fP (\fIstring\fP) \-\- The header value. .UNINDENT .TP .B See \fI\%HTTP.req_rep_header()\fP .UNINDENT .UNINDENT .INDENT 0.0 .TP .B HTTP.req_rep_header(http, name, regex, replace) Matches the regular expression in all occurrences of header field "name" according to "regex", and replaces them with the "replace" argument. The replacement value can contain back references like 1, 2, ... This function works with the request. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBhttp\fP (\fIclass_http\fP) \-\- The related http object. .IP \(bu 2 \fBname\fP (\fIstring\fP) \-\- The header name. .IP \(bu 2 \fBregex\fP (\fIstring\fP) \-\- The match regular expression. .IP \(bu 2 \fBreplace\fP (\fIstring\fP) \-\- The replacement value. .UNINDENT .TP .B See \fI\%HTTP.res_rep_header()\fP .UNINDENT .UNINDENT .INDENT 0.0 .TP .B HTTP.res_rep_header(http, name, regex, string) Matches the regular expression in all occurrences of header field "name" according to "regex", and replaces them with the "replace" argument. The replacement value can contain back references like 1, 2, ... This function works with the request. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBhttp\fP (\fIclass_http\fP) \-\- The related http object. .IP \(bu 2 \fBname\fP (\fIstring\fP) \-\- The header name. .IP \(bu 2 \fBregex\fP (\fIstring\fP) \-\- The match regular expression. .IP \(bu 2 \fBreplace\fP (\fIstring\fP) \-\- The replacement value. .UNINDENT .TP .B See \fI\%HTTP.req_rep_header()\fP .UNINDENT .UNINDENT .INDENT 0.0 .TP .B HTTP.req_set_method(http, method) Rewrites the request method with the parameter "method". .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBhttp\fP (\fIclass_http\fP) \-\- The related http object. .IP \(bu 2 \fBmethod\fP (\fIstring\fP) \-\- The new method. .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B HTTP.req_set_path(http, path) Rewrites the request path with the "path" parameter. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBhttp\fP (\fIclass_http\fP) \-\- The related http object. .IP \(bu 2 \fBpath\fP (\fIstring\fP) \-\- The new path. .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B HTTP.req_set_query(http, query) Rewrites the request\(aqs query string which appears after the first question mark ("?") with the parameter "query". .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBhttp\fP (\fIclass_http\fP) \-\- The related http object. .IP \(bu 2 \fBquery\fP (\fIstring\fP) \-\- The new query. .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B HTTP.req_set_uri(http, uri) Rewrites the request URI with the parameter "uri". .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBhttp\fP (\fIclass_http\fP) \-\- The related http object. .IP \(bu 2 \fBuri\fP (\fIstring\fP) \-\- The new uri. .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B HTTP.res_set_status(http, status[, reason]) Rewrites the response status code with the parameter "code". .sp If no custom reason is provided, it will be generated from the status. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBhttp\fP (\fIclass_http\fP) \-\- The related http object. .IP \(bu 2 \fBstatus\fP (\fIinteger\fP) \-\- The new response status code. .IP \(bu 2 \fBreason\fP (\fIstring\fP) \-\- The new response reason (optional). .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B class TXN() The txn class contain all the functions relative to the http or tcp transaction (Note than a tcp stream is the same than a tcp transaction, but an HTTP transaction is not the same than a tcp stream). .sp The usage of this class permits to retrieve data from the requests, alter it and forward it. .sp All the functions provided by this class are available in the context \fBsample\-fetches\fP and \fBactions\fP\&. .UNINDENT .INDENT 0.0 .TP .B TXN.c .INDENT 7.0 .TP .B Returns An \fI\%Converters class\fP\&. .UNINDENT .sp This attribute contains a Converters class object. .UNINDENT .INDENT 0.0 .TP .B TXN.sc .INDENT 7.0 .TP .B Returns An \fI\%Converters class\fP\&. .UNINDENT .sp This attribute contains a Converters class object. The functions of this object returns always a string. .UNINDENT .INDENT 0.0 .TP .B TXN.f .INDENT 7.0 .TP .B Returns An \fI\%Fetches class\fP\&. .UNINDENT .sp This attribute contains a Fetches class object. .UNINDENT .INDENT 0.0 .TP .B TXN.sf .INDENT 7.0 .TP .B Returns An \fI\%Fetches class\fP\&. .UNINDENT .sp This attribute contains a Fetches class object. The functions of this object returns always a string. .UNINDENT .INDENT 0.0 .TP .B TXN.req .INDENT 7.0 .TP .B Returns An \fI\%Channel class\fP\&. .UNINDENT .sp This attribute contains a channel class object for the request buffer. .UNINDENT .INDENT 0.0 .TP .B TXN.res .INDENT 7.0 .TP .B Returns An \fI\%Channel class\fP\&. .UNINDENT .sp This attribute contains a channel class object for the response buffer. .UNINDENT .INDENT 0.0 .TP .B TXN.http .INDENT 7.0 .TP .B Returns An \fI\%HTTP class\fP\&. .UNINDENT .sp This attribute contains an HTTP class object. It is available only if the proxy has the "mode http" enabled. .UNINDENT .INDENT 0.0 .TP .B TXN.log(TXN, loglevel, msg) This function sends a log. The log is sent, according with the HAProxy configuration file, on the default syslog server if it is configured and on the stderr if it is allowed. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBtxn\fP (\fIclass_txn\fP) \-\- The class txn object containing the data. .IP \(bu 2 \fBloglevel\fP (\fIinteger\fP) \-\- Is the log level associated with the message. It is a number between 0 and 7. .IP \(bu 2 \fBmsg\fP (\fIstring\fP) \-\- The log content. .UNINDENT .TP .B See \fI\%core.emerg\fP, \fI\%core.alert\fP, \fI\%core.crit\fP, \fI\%core.err\fP, \fI\%core.warning\fP, \fI\%core.notice\fP, \fI\%core.info\fP, \fI\%core.debug\fP (log level definitions) .TP .B See \fI\%TXN.deflog()\fP .TP .B See \fI\%TXN.Debug()\fP .TP .B See \fI\%TXN.Info()\fP .TP .B See \fI\%TXN.Warning()\fP .TP .B See \fI\%TXN.Alert()\fP .UNINDENT .UNINDENT .INDENT 0.0 .TP .B TXN.deflog(TXN, msg) Sends a log line with the default loglevel for the proxy associated with the transaction. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBtxn\fP (\fIclass_txn\fP) \-\- The class txn object containing the data. .IP \(bu 2 \fBmsg\fP (\fIstring\fP) \-\- The log content. .UNINDENT .TP .B See :js:func: .nf \(ga .fi TXN.log .UNINDENT .UNINDENT .INDENT 0.0 .TP .B TXN.Debug(txn, msg) .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBtxn\fP (\fIclass_txn\fP) \-\- The class txn object containing the data. .IP \(bu 2 \fBmsg\fP (\fIstring\fP) \-\- The log content. .UNINDENT .TP .B See \fI\%TXN.log()\fP .UNINDENT .sp Does the same job than: .UNINDENT .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C function Debug(txn, msg) TXN.log(txn, core.debug, msg) end .ft P .fi .UNINDENT .UNINDENT .INDENT 0.0 .TP .B TXN.Info(txn, msg) .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBtxn\fP (\fIclass_txn\fP) \-\- The class txn object containing the data. .IP \(bu 2 \fBmsg\fP (\fIstring\fP) \-\- The log content. .UNINDENT .TP .B See \fI\%TXN.log()\fP .UNINDENT .UNINDENT .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C function Debug(txn, msg) TXN.log(txn, core.info, msg) end .ft P .fi .UNINDENT .UNINDENT .INDENT 0.0 .TP .B TXN.Warning(txn, msg) .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBtxn\fP (\fIclass_txn\fP) \-\- The class txn object containing the data. .IP \(bu 2 \fBmsg\fP (\fIstring\fP) \-\- The log content. .UNINDENT .TP .B See \fI\%TXN.log()\fP .UNINDENT .UNINDENT .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C function Debug(txn, msg) TXN.log(txn, core.warning, msg) end .ft P .fi .UNINDENT .UNINDENT .INDENT 0.0 .TP .B TXN.Alert(txn, msg) .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBtxn\fP (\fIclass_txn\fP) \-\- The class txn object containing the data. .IP \(bu 2 \fBmsg\fP (\fIstring\fP) \-\- The log content. .UNINDENT .TP .B See \fI\%TXN.log()\fP .UNINDENT .UNINDENT .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C function Debug(txn, msg) TXN.log(txn, core.alert, msg) end .ft P .fi .UNINDENT .UNINDENT .INDENT 0.0 .TP .B TXN.get_priv(txn) Return Lua data stored in the current transaction (with the \fITXN.set_priv()\fP) function. If no data are stored, it returns a nil value. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBtxn\fP (\fIclass_txn\fP) \-\- The class txn object containing the data. .UNINDENT .TP .B Returns the opaque data previously stored, or nil if nothing is available. .UNINDENT .UNINDENT .INDENT 0.0 .TP .B TXN.set_priv(txn, data) Store any data in the current HAProxy transaction. This action replace the old stored data. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBtxn\fP (\fIclass_txn\fP) \-\- The class txn object containing the data. .IP \(bu 2 \fBdata\fP (\fIopaque\fP) \-\- The data which is stored in the transaction. .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B TXN.set_var(TXN, var, value[, ifexist]) Converts a Lua type in a HAProxy type and store it in a variable . .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBtxn\fP (\fIclass_txn\fP) \-\- The class txn object containing the data. .IP \(bu 2 \fBvar\fP (\fIstring\fP) \-\- The variable name according with the HAProxy variable syntax. .IP \(bu 2 \fBvalue\fP (\fItype\fP) \-\- The value associated to the variable. The type can be string or integer. .IP \(bu 2 \fBifexist\fP (\fIboolean\fP) \-\- If this parameter is set to a truthy value the variable will only be set if it was defined elsewhere (i.e. used within the configuration). It is highly recommended to always set this to true. .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B TXN.unset_var(TXN, var) Unset the variable . .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBtxn\fP (\fIclass_txn\fP) \-\- The class txn object containing the data. .IP \(bu 2 \fBvar\fP (\fIstring\fP) \-\- The variable name according with the HAProxy variable syntax. .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B TXN.get_var(TXN, var) Returns data stored in the variable converter in Lua type. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBtxn\fP (\fIclass_txn\fP) \-\- The class txn object containing the data. .IP \(bu 2 \fBvar\fP (\fIstring\fP) \-\- The variable name according with the HAProxy variable syntax. .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B TXN.reply([reply]) Return a new reply object .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBreply\fP (\fItable\fP) \-\- A table containing info to initialize the reply fields. .UNINDENT .TP .B Returns A \fI\%Reply class\fP object. .UNINDENT .sp The table used to initialized the reply object may contain following entries : .INDENT 7.0 .IP \(bu 2 status : The reply status code. the code 200 is used by default. .IP \(bu 2 reason : The reply reason. The reason corresponding to the status code is used by default. .IP \(bu 2 headers : An list of headers, indexed by header name. Empty by default. For a given name, multiple values are possible, stored in an ordered list. .IP \(bu 2 body : The reply body, empty by default. .UNINDENT .UNINDENT .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C local reply = txn:reply{ status = 400, reason = "Bad request", headers = { ["content\-type"] = { "text/html" }, ["cache\-control"] = {"no\-cache", "no\-store" } }, body = "

invalid request

" } .ft P .fi .UNINDENT .UNINDENT .INDENT 0.0 .TP .B TXN.done(txn[, reply]) This function terminates processing of the transaction and the associated session and optionally reply to the client for HTTP sessions. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBtxn\fP (\fIclass_txn\fP) \-\- The class txn object containing the data. .IP \(bu 2 \fBreply\fP (\fIclass_reply\fP) \-\- The class reply object to return to the client. .UNINDENT .UNINDENT .sp This functions can be used when a critical error is detected or to terminate processing after some data have been returned to the client (eg: a redirect). To do so, a reply may be provided. This object is optional and may contain a status code, a reason, a header list and a body. All these fields are optionnals. When not provided, the default values are used. By default, with an empty reply object, an empty HTTP 200 response is returned to the client. If no reply object is provided, the transaction is terminated without any reply. .sp The reply object may be fully created in lua or the class Reply may be used to create it. .UNINDENT .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C local reply = txn:reply() reply:set_status(400, "Bad request") reply:add_header("content\-type", "text/html") reply:add_header("cache\-control", "no\-cache") reply:add_header("cache\-control", "no\-store") reply:set_body("

invalid request

") txn:done(reply) .ft P .fi .UNINDENT .UNINDENT .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C txn:done{ status = 400, reason = "Bad request", headers = { ["content\-type"] = { "text/html" }, ["cache\-control"] = { "no\-cache", "no\-store" }, }, body = "

invalid request

" } .ft P .fi .UNINDENT .UNINDENT .INDENT 0.0 .INDENT 3.5 \fIWarning\fP: It not make sense to call this function from sample\-fetches. In this case the behaviour of this one is the same than core.done(): it quit the Lua execution. The transaction is really aborted only from an action registered function. .INDENT 0.0 .TP .B see \fI\%TXN.reply()\fP, \fI\%Reply()\fP .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B TXN.set_loglevel(txn, loglevel) Is used to change the log level of the current request. The "loglevel" must be an integer between 0 and 7. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBtxn\fP (\fIclass_txn\fP) \-\- The class txn object containing the data. .IP \(bu 2 \fBloglevel\fP (\fIinteger\fP) \-\- The required log level. This variable can be one of .UNINDENT .TP .B See \fI\%core.emerg\fP, \fI\%core.alert\fP, \fI\%core.crit\fP, \fI\%core.err\fP, \fI\%core.warning\fP, \fI\%core.notice\fP, \fI\%core.info\fP, \fI\%core.debug\fP (log level definitions) .UNINDENT .UNINDENT .INDENT 0.0 .TP .B TXN.set_tos(txn, tos) Is used to set the TOS or DSCP field value of packets sent to the client to the value passed in "tos" on platforms which support this. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBtxn\fP (\fIclass_txn\fP) \-\- The class txn object containing the data. .IP \(bu 2 \fBtos\fP (\fIinteger\fP) \-\- The new TOS os DSCP. .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B TXN.set_mark(txn, mark) Is used to set the Netfilter MARK on all packets sent to the client to the value passed in "mark" on platforms which support it. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBtxn\fP (\fIclass_txn\fP) \-\- The class txn object containing the data. .IP \(bu 2 \fBmark\fP (\fIinteger\fP) \-\- The mark value. .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B TXN.set_priority_class(txn, prio) This function adjusts the priority class of the transaction. The value should be within the range \-2047..2047. Values outside this range will be truncated. .sp See the HAProxy configuration.txt file keyword "http\-request" action "set\-priority\-class" for details. .UNINDENT .INDENT 0.0 .TP .B TXN.set_priority_offset(txn, prio) This function adjusts the priority offset of the transaction. The value should be within the range \-524287..524287. Values outside this range will be truncated. .sp See the HAProxy configuration.txt file keyword "http\-request" action "set\-priority\-offset" for details. .UNINDENT .INDENT 0.0 .TP .B class Reply() \fBcontext\fP: action .sp This class represents an HTTP response message. It provides some methods to enrich it. .UNINDENT .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C local reply = txn:reply({status = 400}) \-\- default HTTP 400 reason\-phase used reply:add_header("content\-type", "text/html") reply:add_header("cache\-control", "no\-cache") reply:add_header("cache\-control", "no\-store") reply:set_body("

invalid request

") .ft P .fi .UNINDENT .UNINDENT .INDENT 0.0 .INDENT 3.5 .INDENT 0.0 .TP .B see \fI\%TXN.reply()\fP .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B Reply.status The reply status code. By default, the status code is set to 200. .INDENT 7.0 .TP .B Returns integer .UNINDENT .UNINDENT .INDENT 0.0 .TP .B Reply.reason The reason string describing the status code. .INDENT 7.0 .TP .B Returns string .UNINDENT .UNINDENT .INDENT 0.0 .TP .B Reply.headers A table indexing all reply headers by name. To each name is associated an ordered list of values. .INDENT 7.0 .TP .B Returns Lua table .UNINDENT .UNINDENT .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C { ["content\-type"] = { "text/html" }, ["cache\-control"] = {"no\-cache", "no\-store" }, x_header_name = { "value1", "value2", ... } ... } .ft P .fi .UNINDENT .UNINDENT .INDENT 0.0 .TP .B Reply.body The reply payload. .INDENT 7.0 .TP .B Returns string .UNINDENT .UNINDENT .INDENT 0.0 .TP .B Reply.set_status(REPLY, status[, reason]) Set the reply status code and optionally the reason\-phrase. If the reason is not provided, the default reason corresponding to the status code is used. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBreply\fP (\fIclass_reply\fP) \-\- The related Reply object. .IP \(bu 2 \fBstatus\fP (\fIinteger\fP) \-\- The reply status code. .IP \(bu 2 \fBreason\fP (\fIstring\fP) \-\- The reply status reason (optional). .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B Reply.add_header(REPLY, name, value) Add a header to the reply object. If the header does not already exist, a new entry is created with its name as index and a one\-element list containing its value as value. Otherwise, the header value is appended to the ordered list of values associated to the header name. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBreply\fP (\fIclass_reply\fP) \-\- The related Reply object. .IP \(bu 2 \fBname\fP (\fIstring\fP) \-\- The header field name. .IP \(bu 2 \fBvalue\fP (\fIstring\fP) \-\- The header field value. .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B Reply.del_header(REPLY, name) Remove all occurrences of a header name from the reply object. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBreply\fP (\fIclass_reply\fP) \-\- The related Reply object. .IP \(bu 2 \fBname\fP (\fIstring\fP) \-\- The header field name. .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B Reply.set_body(REPLY, body) Set the reply payload. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBreply\fP (\fIclass_reply\fP) \-\- The related Reply object. .IP \(bu 2 \fBbody\fP (\fIstring\fP) \-\- The reply payload. .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B class Socket() This class must be compatible with the Lua Socket class. Only the \(aqclient\(aq functions are available. See the Lua Socket documentation: .sp \fI\%http://w3.impa.br/~diego/software/luasocket/tcp.html\fP .UNINDENT .INDENT 0.0 .TP .B Socket.close(socket) Closes a TCP object. The internal socket used by the object is closed and the local address to which the object was bound is made available to other applications. No further operations (except for further calls to the close method) are allowed on a closed Socket. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBsocket\fP (\fIclass_socket\fP) \-\- Is the manipulated Socket. .UNINDENT .UNINDENT .sp Note: It is important to close all used sockets once they are not needed, since, in many systems, each socket uses a file descriptor, which are limited system resources. Garbage\-collected objects are automatically closed before destruction, though. .UNINDENT .INDENT 0.0 .TP .B Socket.connect(socket, address[, port]) Attempts to connect a socket object to a remote host. .sp In case of error, the method returns nil followed by a string describing the error. In case of success, the method returns 1. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBsocket\fP (\fIclass_socket\fP) \-\- Is the manipulated Socket. .IP \(bu 2 \fBaddress\fP (\fIstring\fP) \-\- can be an IP address or a host name. See below for more information. .IP \(bu 2 \fBport\fP (\fIinteger\fP) \-\- must be an integer number in the range [1..64K]. .UNINDENT .TP .B Returns 1 or nil. .UNINDENT .sp An address field extension permits to use the connect() function to connect to other stream than TCP. The syntax containing a simpleipv4 or ipv6 address is the basically expected format. This format requires the port. .sp Other format accepted are a socket path like "/socket/path", it permits to connect to a socket. Abstract namespaces are supported with the prefix "abns@", and finally a file descriptor can be passed with the prefix "fd@". The prefix "ipv4@", "ipv6@" and "unix@" are also supported. The port can be passed int the string. The syntax "127.0.0.1:1234" is valid. In this case, the parameter \fIport\fP must not be set. .UNINDENT .INDENT 0.0 .TP .B Socket.connect_ssl(socket, address, port) Same behavior than the function socket:connect, but uses SSL. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBsocket\fP (\fIclass_socket\fP) \-\- Is the manipulated Socket. .UNINDENT .TP .B Returns 1 or nil. .UNINDENT .UNINDENT .INDENT 0.0 .TP .B Socket.getpeername(socket) Returns information about the remote side of a connected client object. .sp Returns a string with the IP address of the peer, followed by the port number that peer is using for the connection. In case of error, the method returns nil. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBsocket\fP (\fIclass_socket\fP) \-\- Is the manipulated Socket. .UNINDENT .TP .B Returns a string containing the server information. .UNINDENT .UNINDENT .INDENT 0.0 .TP .B Socket.getsockname(socket) Returns the local address information associated to the object. .sp The method returns a string with local IP address and a number with the port. In case of error, the method returns nil. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBsocket\fP (\fIclass_socket\fP) \-\- Is the manipulated Socket. .UNINDENT .TP .B Returns a string containing the client information. .UNINDENT .UNINDENT .INDENT 0.0 .TP .B Socket.receive(socket[, pattern[, prefix]]) Reads data from a client object, according to the specified read pattern. Patterns follow the Lua file I/O format, and the difference in performance between all patterns is negligible. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBsocket\fP (\fIclass_socket\fP) \-\- Is the manipulated Socket. .IP \(bu 2 \fBpattern\fP (\fIstring|integer\fP) \-\- Describe what is required (see below). .IP \(bu 2 \fBprefix\fP (\fIstring\fP) \-\- A string which will be prefix the returned data. .UNINDENT .TP .B Returns a string containing the required data or nil. .UNINDENT .sp Pattern can be any of the following: .INDENT 7.0 .IP \(bu 2 .INDENT 2.0 .TP \fB\(ga*a\(ga\fP: reads from the socket until the connection is closed. No end\-of\-line translation is performed; .UNINDENT .IP \(bu 2 .INDENT 2.0 .TP \fB\(ga*l\(ga\fP: reads a line of text from the Socket. The line is terminated by a LF character (ASCII 10), optionally preceded by a CR character (ASCII 13). The CR and LF characters are not included in the returned line. In fact, all CR characters are ignored by the pattern. This is the default pattern. .UNINDENT .IP \(bu 2 .INDENT 2.0 .TP \fBnumber\fP: causes the method to read a specified number of bytes from the Socket. Prefix is an optional string to be concatenated to the beginning of any received data before return. .UNINDENT .IP \(bu 2 \fBempty\fP: If the pattern is left empty, the default option is \fI*l\fP\&. .UNINDENT .sp If successful, the method returns the received pattern. In case of error, the method returns nil followed by an error message which can be the string \(aqclosed\(aq in case the connection was closed before the transmission was completed or the string \(aqtimeout\(aq in case there was a timeout during the operation. Also, after the error message, the function returns the partial result of the transmission. .sp Important note: This function was changed severely. It used to support multiple patterns (but I have never seen this feature used) and now it doesn\(aqt anymore. Partial results used to be returned in the same way as successful results. This last feature violated the idea that all functions should return nil on error. Thus it was changed too. .UNINDENT .INDENT 0.0 .TP .B Socket.send(socket, data[, start[, end]]) Sends data through client object. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBsocket\fP (\fIclass_socket\fP) \-\- Is the manipulated Socket. .IP \(bu 2 \fBdata\fP (\fIstring\fP) \-\- The data that will be sent. .IP \(bu 2 \fBstart\fP (\fIinteger\fP) \-\- The start position in the buffer of the data which will be sent. .IP \(bu 2 \fBend\fP (\fIinteger\fP) \-\- The end position in the buffer of the data which will be sent. .UNINDENT .TP .B Returns see below. .UNINDENT .sp Data is the string to be sent. The optional arguments i and j work exactly like the standard string.sub Lua function to allow the selection of a substring to be sent. .sp If successful, the method returns the index of the last byte within [start, end] that has been sent. Notice that, if start is 1 or absent, this is effectively the total number of bytes sent. In case of error, the method returns nil, followed by an error message, followed by the index of the last byte within [start, end] that has been sent. You might want to try again from the byte following that. The error message can be \(aqclosed\(aq in case the connection was closed before the transmission was completed or the string \(aqtimeout\(aq in case there was a timeout during the operation. .sp Note: Output is not buffered. For small strings, it is always better to concatenate them in Lua (with the \(aq..\(aq operator) and send the result in one call instead of calling the method several times. .UNINDENT .INDENT 0.0 .TP .B Socket.setoption(socket, option[, value]) Just implemented for compatibility, this cal does nothing. .UNINDENT .INDENT 0.0 .TP .B Socket.settimeout(socket, value[, mode]) Changes the timeout values for the object. All I/O operations are blocking. That is, any call to the methods send, receive, and accept will block indefinitely, until the operation completes. The settimeout method defines a limit on the amount of time the I/O methods can block. When a timeout time has elapsed, the affected methods give up and fail with an error code. .sp The amount of time to wait is specified as the value parameter, in seconds. .sp The timeout modes are not implemented, the only settable timeout is the inactivity time waiting for complete the internal buffer send or waiting for receive data. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBsocket\fP (\fIclass_socket\fP) \-\- Is the manipulated Socket. .IP \(bu 2 \fBvalue\fP (\fIfloat\fP) \-\- The timeout value. Use floating point to specify milliseconds. .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B class Regex() This class allows the usage of HAProxy regexes because classic lua doesn\(aqt provides regexes. This class inherits the HAProxy compilation options, so the regexes can be libc regex, pcre regex or pcre JIT regex. .sp The expression matching number is limited to 20 per regex. The only available option is case sensitive. .sp Because regexes compilation is a heavy process, it is better to define all your regexes in the \fBbody context\fP and use it during the runtime. .UNINDENT .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C \-\- Create the regex st, regex = Regex.new("needle (..) (...)", true); \-\- Check compilation errors if st == false then print "error: " .. regex end \-\- Match the regexes print(regex:exec("Looking for a needle in the haystack")) \-\- true print(regex:exec("Lokking for a cat in the haystack")) \-\- false \-\- Extract words st, list = regex:match("Looking for a needle in the haystack") print(st) \-\- true print(list[1]) \-\- needle in the print(list[2]) \-\- in print(list[3]) \-\- the .ft P .fi .UNINDENT .UNINDENT .INDENT 0.0 .TP .B Regex.new(regex, case_sensitive) Create and compile a regex. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBregex\fP (\fIstring\fP) \-\- The regular expression according with the libc or pcre standard .IP \(bu 2 \fBcase_sensitive\fP (\fIboolean\fP) \-\- Match is case sensitive or not. .UNINDENT .TP .B Returns boolean status and \fI\%Regex class\fP or string containing fail reason. .UNINDENT .UNINDENT .INDENT 0.0 .TP .B Regex.exec(regex, str) Execute the regex. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBregex\fP (\fIclass_regex\fP) \-\- A \fI\%Regex class\fP object. .IP \(bu 2 \fBstr\fP (\fIstring\fP) \-\- The input string will be compared with the compiled regex. .UNINDENT .TP .B Returns a boolean status according with the match result. .UNINDENT .UNINDENT .INDENT 0.0 .TP .B Regex.match(regex, str) Execute the regex and return matched expressions. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBmap\fP (\fIclass_map\fP) \-\- A \fI\%Regex class\fP object. .IP \(bu 2 \fBstr\fP (\fIstring\fP) \-\- The input string will be compared with the compiled regex. .UNINDENT .TP .B Returns a boolean status according with the match result, and a table containing all the string matched in order of declaration. .UNINDENT .UNINDENT .INDENT 0.0 .TP .B class Map() This class permits to do some lookup in HAProxy maps. The declared maps can be modified during the runtime through the HAProxy management socket. .UNINDENT .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C default = "usa" \-\- Create and load map geo = Map.new("geo.map", Map._ip); \-\- Create new fetch that returns the user country core.register_fetches("country", function(txn) local src; local loc; src = txn.f:fhdr("x\-forwarded\-for"); if (src == nil) then src = txn.f:src() if (src == nil) then return default; end end \-\- Perform lookup loc = geo:lookup(src); if (loc == nil) then return default; end return loc; end); .ft P .fi .UNINDENT .UNINDENT .INDENT 0.0 .TP .B Map._int See the HAProxy configuration.txt file, chapter "Using ACLs and fetching samples" and subchapter "ACL basics" to understand this pattern matching method. .sp Note that \fBMap.int\fP is also available for compatibility. .UNINDENT .INDENT 0.0 .TP .B Map._ip See the HAProxy configuration.txt file, chapter "Using ACLs and fetching samples" and subchapter "ACL basics" to understand this pattern matching method. .sp Note that \fBMap.ip\fP is also available for compatibility. .UNINDENT .INDENT 0.0 .TP .B Map._str See the HAProxy configuration.txt file, chapter "Using ACLs and fetching samples" and subchapter "ACL basics" to understand this pattern matching method. .sp Note that \fBMap.str\fP is also available for compatibility. .UNINDENT .INDENT 0.0 .TP .B Map._beg See the HAProxy configuration.txt file, chapter "Using ACLs and fetching samples" and subchapter "ACL basics" to understand this pattern matching method. .sp Note that \fBMap.beg\fP is also available for compatibility. .UNINDENT .INDENT 0.0 .TP .B Map._sub See the HAProxy configuration.txt file, chapter "Using ACLs and fetching samples" and subchapter "ACL basics" to understand this pattern matching method. .sp Note that \fBMap.sub\fP is also available for compatibility. .UNINDENT .INDENT 0.0 .TP .B Map._dir See the HAProxy configuration.txt file, chapter "Using ACLs and fetching samples" and subchapter "ACL basics" to understand this pattern matching method. .sp Note that \fBMap.dir\fP is also available for compatibility. .UNINDENT .INDENT 0.0 .TP .B Map._dom See the HAProxy configuration.txt file, chapter "Using ACLs and fetching samples" and subchapter "ACL basics" to understand this pattern matching method. .sp Note that \fBMap.dom\fP is also available for compatibility. .UNINDENT .INDENT 0.0 .TP .B Map._end See the HAProxy configuration.txt file, chapter "Using ACLs and fetching samples" and subchapter "ACL basics" to understand this pattern matching method. .UNINDENT .INDENT 0.0 .TP .B Map._reg See the HAProxy configuration.txt file, chapter "Using ACLs and fetching samples" and subchapter "ACL basics" to understand this pattern matching method. .sp Note that \fBMap.reg\fP is also available for compatibility. .UNINDENT .INDENT 0.0 .TP .B Map.new(file, method) Creates and load a map. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBfile\fP (\fIstring\fP) \-\- Is the file containing the map. .IP \(bu 2 \fBmethod\fP (\fIinteger\fP) \-\- Is the map pattern matching method. See the attributes of the Map class. .UNINDENT .TP .B Returns a class Map object. .TP .B See The Map attributes: \fI\%Map._int\fP, \fI\%Map._ip\fP, \fI\%Map._str\fP, \fI\%Map._beg\fP, \fI\%Map._sub\fP, \fI\%Map._dir\fP, \fI\%Map._dom\fP, \fI\%Map._end\fP and \fI\%Map._reg\fP\&. .UNINDENT .UNINDENT .INDENT 0.0 .TP .B Map.lookup(map, str) Perform a lookup in a map. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBmap\fP (\fIclass_map\fP) \-\- Is the class Map object. .IP \(bu 2 \fBstr\fP (\fIstring\fP) \-\- Is the string used as key. .UNINDENT .TP .B Returns a string containing the result or nil if no match. .UNINDENT .UNINDENT .INDENT 0.0 .TP .B Map.slookup(map, str) Perform a lookup in a map. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBmap\fP (\fIclass_map\fP) \-\- Is the class Map object. .IP \(bu 2 \fBstr\fP (\fIstring\fP) \-\- Is the string used as key. .UNINDENT .TP .B Returns a string containing the result or empty string if no match. .UNINDENT .UNINDENT .INDENT 0.0 .TP .B class AppletHTTP() This class is used with applets that requires the \(aqhttp\(aq mode. The http applet can be registered with the \fIcore.register_service()\fP function. They are used for processing an http request like a server in back of HAProxy. .sp This is an hello world sample code: .UNINDENT .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C core.register_service("hello\-world", "http", function(applet) local response = "Hello World !" applet:set_status(200) applet:add_header("content\-length", string.len(response)) applet:add_header("content\-type", "text/plain") applet:start_response() applet:send(response) end) .ft P .fi .UNINDENT .UNINDENT .INDENT 0.0 .TP .B AppletHTTP.c .INDENT 7.0 .TP .B Returns A \fI\%Converters class\fP .UNINDENT .sp This attribute contains a Converters class object. .UNINDENT .INDENT 0.0 .TP .B AppletHTTP.sc .INDENT 7.0 .TP .B Returns A \fI\%Converters class\fP .UNINDENT .sp This attribute contains a Converters class object. The functions of this object returns always a string. .UNINDENT .INDENT 0.0 .TP .B AppletHTTP.f .INDENT 7.0 .TP .B Returns A \fI\%Fetches class\fP .UNINDENT .sp This attribute contains a Fetches class object. Note that the applet execution place cannot access to a valid HAProxy core HTTP transaction, so some sample fetches related to the HTTP dependent values (hdr, path, ...) are not available. .UNINDENT .INDENT 0.0 .TP .B AppletHTTP.sf .INDENT 7.0 .TP .B Returns A \fI\%Fetches class\fP .UNINDENT .sp This attribute contains a Fetches class object. The functions of this object returns always a string. Note that the applet execution place cannot access to a valid HAProxy core HTTP transaction, so some sample fetches related to the HTTP dependent values (hdr, path, ...) are not available. .UNINDENT .INDENT 0.0 .TP .B AppletHTTP.method .INDENT 7.0 .TP .B Returns string .UNINDENT .sp The attribute method returns a string containing the HTTP method. .UNINDENT .INDENT 0.0 .TP .B AppletHTTP.version .INDENT 7.0 .TP .B Returns string .UNINDENT .sp The attribute version, returns a string containing the HTTP request version. .UNINDENT .INDENT 0.0 .TP .B AppletHTTP.path .INDENT 7.0 .TP .B Returns string .UNINDENT .sp The attribute path returns a string containing the HTTP request path. .UNINDENT .INDENT 0.0 .TP .B AppletHTTP.qs .INDENT 7.0 .TP .B Returns string .UNINDENT .sp The attribute qs returns a string containing the HTTP request query string. .UNINDENT .INDENT 0.0 .TP .B AppletHTTP.length .INDENT 7.0 .TP .B Returns integer .UNINDENT .sp The attribute length returns an integer containing the HTTP body length. .UNINDENT .INDENT 0.0 .TP .B AppletHTTP.headers .INDENT 7.0 .TP .B Returns table .UNINDENT .sp The attribute headers returns a table containing the HTTP headers. The header names are always in lower case. As the header name can be encountered more than once in each request, the value is indexed with 0 as first index value. The table have this form: .UNINDENT .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C AppletHTTP.headers[\(aq\(aq][] = "" AppletHTTP.headers["host"][0] = "www.test.com" AppletHTTP.headers["accept"][0] = "audio/basic q=1" AppletHTTP.headers["accept"][1] = "audio/*, q=0.2" AppletHTTP.headers["accept"][2] = "*/*, q=0.1" .ft P .fi .UNINDENT .UNINDENT .INDENT 0.0 .TP .B AppletHTTP.set_status(applet, code[, reason]) This function sets the HTTP status code for the response. The allowed code are from 100 to 599. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBapplet\fP (\fIclass_AppletHTTP\fP) \-\- An \fI\%AppletHTTP class\fP .IP \(bu 2 \fBcode\fP (\fIinteger\fP) \-\- the status code returned to the client. .IP \(bu 2 \fBreason\fP (\fIstring\fP) \-\- the status reason returned to the client (optional). .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B AppletHTTP.add_header(applet, name, value) This function add an header in the response. Duplicated headers are not collapsed. The special header \fIcontent\-length\fP is used to determinate the response length. If it not exists, a \fItransfer\-encoding: chunked\fP is set, and all the write from the function \fIAppletHTTP:send()\fP become a chunk. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBapplet\fP (\fIclass_AppletHTTP\fP) \-\- An \fI\%AppletHTTP class\fP .IP \(bu 2 \fBname\fP (\fIstring\fP) \-\- the header name .IP \(bu 2 \fBvalue\fP (\fIstring\fP) \-\- the header value .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B AppletHTTP.start_response(applet) This function indicates to the HTTP engine that it can process and send the response headers. After this called we cannot add headers to the response; We cannot use the \fIAppletHTTP:send()\fP function if the \fIAppletHTTP:start_response()\fP is not called. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBapplet\fP (\fIclass_AppletHTTP\fP) \-\- An \fI\%AppletHTTP class\fP .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B AppletHTTP.getline(applet) This function returns a string containing one line from the http body. If the data returned doesn\(aqt contains a final \(aq\en\(aq its assumed than its the last available data before the end of stream. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBapplet\fP (\fIclass_AppletHTTP\fP) \-\- An \fI\%AppletHTTP class\fP .UNINDENT .TP .B Returns a string. The string can be empty if we reach the end of the stream. .UNINDENT .UNINDENT .INDENT 0.0 .TP .B AppletHTTP.receive(applet[, size]) Reads data from the HTTP body, according to the specified read \fIsize\fP\&. If the \fIsize\fP is missing, the function tries to read all the content of the stream until the end. If the \fIsize\fP is bigger than the http body, it returns the amount of data available. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBapplet\fP (\fIclass_AppletHTTP\fP) \-\- An \fI\%AppletHTTP class\fP .IP \(bu 2 \fBsize\fP (\fIinteger\fP) \-\- the required read size. .UNINDENT .TP .B Returns always return a string,the string can be empty is the connection is closed. .UNINDENT .UNINDENT .INDENT 0.0 .TP .B AppletHTTP.send(applet, msg) Send the message \fImsg\fP on the http request body. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBapplet\fP (\fIclass_AppletHTTP\fP) \-\- An \fI\%AppletHTTP class\fP .IP \(bu 2 \fBmsg\fP (\fIstring\fP) \-\- the message to send. .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B AppletHTTP.get_priv(applet) Return Lua data stored in the current transaction. If no data are stored, it returns a nil value. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBapplet\fP (\fIclass_AppletHTTP\fP) \-\- An \fI\%AppletHTTP class\fP .UNINDENT .TP .B Returns the opaque data previously stored, or nil if nothing is available. .TP .B See \fI\%AppletHTTP.set_priv()\fP .UNINDENT .UNINDENT .INDENT 0.0 .TP .B AppletHTTP.set_priv(applet, data) Store any data in the current HAProxy transaction. This action replace the old stored data. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBapplet\fP (\fIclass_AppletHTTP\fP) \-\- An \fI\%AppletHTTP class\fP .IP \(bu 2 \fBdata\fP (\fIopaque\fP) \-\- The data which is stored in the transaction. .UNINDENT .TP .B See \fI\%AppletHTTP.get_priv()\fP .UNINDENT .UNINDENT .INDENT 0.0 .TP .B AppletHTTP.set_var(applet, var, value[, ifexist]) Converts a Lua type in a HAProxy type and store it in a variable . .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBapplet\fP (\fIclass_AppletHTTP\fP) \-\- An \fI\%AppletHTTP class\fP .IP \(bu 2 \fBvar\fP (\fIstring\fP) \-\- The variable name according with the HAProxy variable syntax. .IP \(bu 2 \fBvalue\fP (\fItype\fP) \-\- The value associated to the variable. The type ca be string or integer. .IP \(bu 2 \fBifexist\fP (\fIboolean\fP) \-\- If this parameter is set to a truthy value the variable will only be set if it was defined elsewhere (i.e. used within the configuration). It is highly recommended to always set this to true. .UNINDENT .TP .B See \fI\%AppletHTTP.unset_var()\fP .TP .B See \fI\%AppletHTTP.get_var()\fP .UNINDENT .UNINDENT .INDENT 0.0 .TP .B AppletHTTP.unset_var(applet, var) Unset the variable . .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBapplet\fP (\fIclass_AppletHTTP\fP) \-\- An \fI\%AppletHTTP class\fP .IP \(bu 2 \fBvar\fP (\fIstring\fP) \-\- The variable name according with the HAProxy variable syntax. .UNINDENT .TP .B See \fI\%AppletHTTP.set_var()\fP .TP .B See \fI\%AppletHTTP.get_var()\fP .UNINDENT .UNINDENT .INDENT 0.0 .TP .B AppletHTTP.get_var(applet, var) Returns data stored in the variable converter in Lua type. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBapplet\fP (\fIclass_AppletHTTP\fP) \-\- An \fI\%AppletHTTP class\fP .IP \(bu 2 \fBvar\fP (\fIstring\fP) \-\- The variable name according with the HAProxy variable syntax. .UNINDENT .TP .B See \fI\%AppletHTTP.set_var()\fP .TP .B See \fI\%AppletHTTP.unset_var()\fP .UNINDENT .UNINDENT .INDENT 0.0 .TP .B class AppletTCP() This class is used with applets that requires the \(aqtcp\(aq mode. The tcp applet can be registered with the \fIcore.register_service()\fP function. They are used for processing a tcp stream like a server in back of HAProxy. .UNINDENT .INDENT 0.0 .TP .B AppletTCP.c .INDENT 7.0 .TP .B Returns A \fI\%Converters class\fP .UNINDENT .sp This attribute contains a Converters class object. .UNINDENT .INDENT 0.0 .TP .B AppletTCP.sc .INDENT 7.0 .TP .B Returns A \fI\%Converters class\fP .UNINDENT .sp This attribute contains a Converters class object. The functions of this object returns always a string. .UNINDENT .INDENT 0.0 .TP .B AppletTCP.f .INDENT 7.0 .TP .B Returns A \fI\%Fetches class\fP .UNINDENT .sp This attribute contains a Fetches class object. .UNINDENT .INDENT 0.0 .TP .B AppletTCP.sf .INDENT 7.0 .TP .B Returns A \fI\%Fetches class\fP .UNINDENT .sp This attribute contains a Fetches class object. .UNINDENT .INDENT 0.0 .TP .B AppletTCP.getline(applet) This function returns a string containing one line from the stream. If the data returned doesn\(aqt contains a final \(aq\en\(aq its assumed than its the last available data before the end of stream. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBapplet\fP (\fIclass_AppletTCP\fP) \-\- An \fI\%AppletTCP class\fP .UNINDENT .TP .B Returns a string. The string can be empty if we reach the end of the stream. .UNINDENT .UNINDENT .INDENT 0.0 .TP .B AppletTCP.receive(applet[, size]) Reads data from the TCP stream, according to the specified read \fIsize\fP\&. If the \fIsize\fP is missing, the function tries to read all the content of the stream until the end. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBapplet\fP (\fIclass_AppletTCP\fP) \-\- An \fI\%AppletTCP class\fP .IP \(bu 2 \fBsize\fP (\fIinteger\fP) \-\- the required read size. .UNINDENT .TP .B Returns always return a string,the string can be empty is the connection is closed. .UNINDENT .UNINDENT .INDENT 0.0 .TP .B AppletTCP.send(appletmsg) Send the message on the stream. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBapplet\fP (\fIclass_AppletTCP\fP) \-\- An \fI\%AppletTCP class\fP .IP \(bu 2 \fBmsg\fP (\fIstring\fP) \-\- the message to send. .UNINDENT .UNINDENT .UNINDENT .INDENT 0.0 .TP .B AppletTCP.get_priv(applet) Return Lua data stored in the current transaction. If no data are stored, it returns a nil value. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBapplet\fP (\fIclass_AppletTCP\fP) \-\- An \fI\%AppletTCP class\fP .UNINDENT .TP .B Returns the opaque data previously stored, or nil if nothing is available. .TP .B See \fI\%AppletTCP.set_priv()\fP .UNINDENT .UNINDENT .INDENT 0.0 .TP .B AppletTCP.set_priv(applet, data) Store any data in the current HAProxy transaction. This action replace the old stored data. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBapplet\fP (\fIclass_AppletTCP\fP) \-\- An \fI\%AppletTCP class\fP .IP \(bu 2 \fBdata\fP (\fIopaque\fP) \-\- The data which is stored in the transaction. .UNINDENT .TP .B See \fI\%AppletTCP.get_priv()\fP .UNINDENT .UNINDENT .INDENT 0.0 .TP .B AppletTCP.set_var(applet, var, value[, ifexist]) Converts a Lua type in a HAProxy type and stores it in a variable . .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBapplet\fP (\fIclass_AppletTCP\fP) \-\- An \fI\%AppletTCP class\fP .IP \(bu 2 \fBvar\fP (\fIstring\fP) \-\- The variable name according with the HAProxy variable syntax. .IP \(bu 2 \fBvalue\fP (\fItype\fP) \-\- The value associated to the variable. The type can be string or integer. .IP \(bu 2 \fBifexist\fP (\fIboolean\fP) \-\- If this parameter is set to a truthy value the variable will only be set if it was defined elsewhere (i.e. used within the configuration). It is highly recommended to always set this to true. .UNINDENT .TP .B See \fI\%AppletTCP.unset_var()\fP .TP .B See \fI\%AppletTCP.get_var()\fP .UNINDENT .UNINDENT .INDENT 0.0 .TP .B AppletTCP.unset_var(applet, var) Unsets the variable . .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBapplet\fP (\fIclass_AppletTCP\fP) \-\- An \fI\%AppletTCP class\fP .IP \(bu 2 \fBvar\fP (\fIstring\fP) \-\- The variable name according with the HAProxy variable syntax. .UNINDENT .TP .B See \fI\%AppletTCP.unset_var()\fP .TP .B See \fI\%AppletTCP.set_var()\fP .UNINDENT .UNINDENT .INDENT 0.0 .TP .B AppletTCP.get_var(applet, var) Returns data stored in the variable converter in Lua type. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBapplet\fP (\fIclass_AppletTCP\fP) \-\- An \fI\%AppletTCP class\fP .IP \(bu 2 \fBvar\fP (\fIstring\fP) \-\- The variable name according with the HAProxy variable syntax. .UNINDENT .TP .B See \fI\%AppletTCP.unset_var()\fP .TP .B See \fI\%AppletTCP.set_var()\fP .UNINDENT .UNINDENT .INDENT 0.0 .TP .B class StickTable() \fBcontext\fP: task, action, sample\-fetch .sp This class can be used to access the HAProxy stick tables from Lua. .UNINDENT .INDENT 0.0 .TP .B StickTable.info() Returns stick table attributes as a Lua table. See HAProxy documentation for "stick\-table" for canonical info, or check out example bellow. .INDENT 7.0 .TP .B Returns Lua table .UNINDENT .sp Assume our table has IPv4 key and gpc0 and conn_rate "columns": .UNINDENT .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C { expire=, # Value in ms size=, # Maximum table size used=, # Actual number of entries in table data={ # Data columns, with types as key, and periods as values (\-1 if type is not rate counter) conn_rate=, gpc0=\-1 }, length=, # max string length for string table keys, key length # otherwise nopurge=, # purge oldest entries when table is full type="ip" # can be "ip", "ipv6", "integer", "string", "binary" } .ft P .fi .UNINDENT .UNINDENT .INDENT 0.0 .TP .B StickTable.lookup(key) Returns stick table entry for given .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBkey\fP (\fIstring\fP) \-\- Stick table key (IP addresses and strings are supported) .UNINDENT .TP .B Returns Lua table .UNINDENT .UNINDENT .INDENT 0.0 .TP .B StickTable.dump([filter]) Returns all entries in stick table. An optional filter can be used to extract entries with specific data values. Filter is a table with valid comparison operators as keys followed by data type name and value pairs. Check out the HAProxy docs for "show table" for more details. For the reference, the supported operators are: .INDENT 7.0 .INDENT 3.5 "eq", "ne", "le", "lt", "ge", "gt" .UNINDENT .UNINDENT .sp For large tables, execution of this function can take a long time (for HAProxy standards). That\(aqs also true when filter is used, so take care and measure the impact. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBfilter\fP (\fItable\fP) \-\- Stick table filter .UNINDENT .TP .B Returns Stick table entries (table) .UNINDENT .sp See below for example filter, which contains 4 entries (or comparisons). (Maximum number of filter entries is 4, defined in the source code) .UNINDENT .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C local filter = { {"gpc0", "gt", 30}, {"gpc1", "gt", 20}}, {"conn_rate", "le", 10} } .ft P .fi .UNINDENT .UNINDENT .INDENT 0.0 .TP .B class Act() \fBcontext\fP: action .sp This class contains all return codes an action may return. It is the lua equivalent to HAProxy "ACT_RET_*" code. .UNINDENT .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C core.register_action("deny", { "http\-req" }, function (txn) return act.DENY end) .ft P .fi .UNINDENT .UNINDENT .INDENT 0.0 .TP .B act.CONTINUE This attribute is an integer (0). It instructs HAProxy to continue the current ruleset processing on the message. It is the default return code for a lua action. .INDENT 7.0 .TP .B Returns integer .UNINDENT .UNINDENT .INDENT 0.0 .TP .B act.STOP This attribute is an integer (1). It instructs HAProxy to stop the current ruleset processing on the message. .UNINDENT .INDENT 0.0 .TP .B act.YIELD This attribute is an integer (2). It instructs HAProxy to temporarily pause the message processing. It will be resumed later on the same rule. The corresponding lua script is re\-executed for the start. .UNINDENT .INDENT 0.0 .TP .B act.ERROR This attribute is an integer (3). It triggers an internal errors The message processing is stopped and the transaction is terminated. For HTTP streams, an HTTP 500 error is returned to the client. .INDENT 7.0 .TP .B Returns integer .UNINDENT .UNINDENT .INDENT 0.0 .TP .B act.DONE This attribute is an integer (4). It instructs HAProxy to stop the message processing. .INDENT 7.0 .TP .B Returns integer .UNINDENT .UNINDENT .INDENT 0.0 .TP .B act.DENY This attribute is an integer (5). It denies the current message. The message processing is stopped and the transaction is terminated. For HTTP streams, an HTTP 403 error is returned to the client if the deny is returned during the request analysis. During the response analysis, an HTTP 502 error is returned and the server response is discarded. .INDENT 7.0 .TP .B Returns integer .UNINDENT .UNINDENT .INDENT 0.0 .TP .B act.ABORT This attribute is an integer (6). It aborts the current message. The message processing is stopped and the transaction is terminated. For HTTP streams, HAproxy assumes a response was already sent to the client. From the Lua actions point of view, when this code is used, the transaction is terminated with no reply. .INDENT 7.0 .TP .B Returns integer .UNINDENT .UNINDENT .INDENT 0.0 .TP .B act.INVALID This attribute is an integer (7). It triggers an internal errors. The message processing is stopped and the transaction is terminated. For HTTP streams, an HTTP 400 error is returned to the client if the error is returned during the request analysis. During the response analysis, an HTTP 502 error is returned and the server response is discarded. .INDENT 7.0 .TP .B Returns integer .UNINDENT .UNINDENT .INDENT 0.0 .TP .B act:wake_time(milliseconds) \fBcontext\fP: action .sp Set the script pause timeout to the specified time, defined in milliseconds. .INDENT 7.0 .TP .B Arguments .INDENT 7.0 .IP \(bu 2 \fBmilliseconds\fP (\fIinteger\fP) \-\- the required milliseconds. .UNINDENT .UNINDENT .sp This function may be used when a lua action returns \fIact.YIELD\fP, to force its wake\-up at most after the specified number of milliseconds. .UNINDENT .sp A lot of useful lua libraries can be found here: .INDENT 0.0 .IP \(bu 2 \fI\%https://lua\-toolbox.com/\fP .UNINDENT .sp Redis client library: .INDENT 0.0 .IP \(bu 2 \fI\%https://github.com/nrk/redis\-lua\fP .UNINDENT .sp This is an example about the usage of the Redis library with HAProxy. Note that each call of any function of this library can throw an error if the socket connection fails. .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C \-\- load the redis library local redis = require("redis"); function do_something(txn) \-\- create and connect new tcp socket local tcp = core.tcp(); tcp:settimeout(1); tcp:connect("127.0.0.1", 6379); \-\- use the redis library with this new socket local client = redis.connect({socket=tcp}); client:ping(); end .ft P .fi .UNINDENT .UNINDENT .sp OpenSSL: .INDENT 0.0 .IP \(bu 2 \fI\%http://mkottman.github.io/luacrypto/index.html\fP .IP \(bu 2 \fI\%https://github.com/brunoos/luasec/wiki\fP .UNINDENT .SH AUTHOR Thierry FOURNIER .SH COPYRIGHT 2023, Thierry FOURNIER .\" Generated by docutils manpage writer. .