haproxy/doc
Christopher Faulet 700d9e88ad MEDIUM: lua: Add ability for actions to intercept HTTP messages
It is now possible to intercept HTTP messages from a lua action and reply to
clients. To do so, a reply object must be provided to the function
txn:done(). It may contain a status code with a reason, a header list and a
body. By default, if an empty reply object is used, an empty 200 response is
returned. If no reply is passed when txn:done() is called, the previous
behaviour is respected, the transaction is terminated and nothing is returned to
the client. The same is done for TCP streams. When txn:done() is called, the
action is terminated with the code ACT_RET_DONE on success and ACT_RET_ERR on
error, interrupting the message analysis.

The reply object may be created for the lua, by hand. Or txn:reply() may be
called. If so, this object provides some methods to fill it:

  * Reply:set_status(<status> [  <reason>]) : Set the status and optionally the
   reason. If no reason is provided, the default one corresponding to the status
   code is used.

  * Reply:add_header(<name>, <value>) : Add a header. For a given name, the
    values are stored in an ordered list.

  * Reply:del_header(<name>) : Removes all occurrences of a header name.

  * Reply:set_body(<body>) : Set the reply body.

Here are some examples, all doing the same:

    -- ex. 1
    txn:done{
        status  = 400,
        reason  = "Bad request",
        headers = {
            ["content-type"]  = { "text/html" },
            ["cache-control"] = { "no-cache", "no-store" },
        },
        body = "<html><body><h1>invalid request<h1></body></html>"
    }

    -- ex. 2
    local reply = txn:reply{
        status  = 400,
        reason  = "Bad request",
        headers = {
            ["content-type"]  = { "text/html" },
            ["cache-control"] = { "no-cache", "no-store" }
        },
        body = "<html><body><h1>invalid request<h1></body></html>"
    }
    txn:done(reply)

    -- ex. 3
    local reply = txn:reply()
    reply:set_status(400, "Bad request")
    reply:add_header("content-length", "text/html")
    reply:add_header("cache-control", "no-cache")
    reply:add_header("cache-control", "no-store")
    reply:set_body("<html><body><h1>invalid request<h1></body></html>")
    txn:done(reply)
2020-02-06 15:13:04 +01:00
..
design-thoughts
internals [RELEASE] Released version 2.2-dev1 2020-01-22 10:34:58 +01:00
lua-api MEDIUM: lua: Add ability for actions to intercept HTTP messages 2020-02-06 15:13:04 +01:00
51Degrees-device-detection.txt CLEANUP: 51d: move the 51d dummy lib to contrib/51d/src to match the real lib 2019-06-13 15:56:10 +02:00
acl.fig
architecture.txt
close-options.txt
coding-style.txt DOC: fix typos 2019-05-25 07:34:24 +02:00
configuration.txt MEDIUM: http-rules: Support extra headers for HTTP return actions 2020-02-06 15:13:03 +01:00
cookie-options.txt
DeviceAtlas-device-detection.txt DOC: fix typos 2019-05-25 07:34:24 +02:00
gpl.txt
haproxy.1 MINOR: doc: update the manpage and usage message about -S 2019-06-13 17:09:27 +02:00
intro.txt DOC: remove references to the outdated architecture.txt 2019-12-11 11:55:52 +01:00
lgpl.txt
linux-syn-cookies.txt
lua.txt DOC: update few references to the linux* targets and change them to linux-glibc 2019-06-15 18:03:48 +02:00
management.txt MEDIUM: cli: Allow multiple filter entries for "show table" 2020-01-22 14:33:17 +01:00
netscaler-client-ip-insertion-protocol.txt DOC: fix typos 2019-05-25 07:34:24 +02:00
network-namespaces.txt
peers-v2.0.txt DOC: fix typos 2019-05-25 07:34:24 +02:00
peers.txt DOC: peers: Update for dictionary cache entries for peers protocol. 2019-06-07 15:47:54 +02:00
proxy-protocol.txt DOC: fix typos 2019-05-25 07:34:24 +02:00
queuing.fig
regression-testing.txt DOC: fix typos 2019-05-25 07:34:24 +02:00
seamless_reload.txt CLEANUP: removed obsolete examples an move a few to better places 2019-06-15 21:25:06 +02:00
SOCKS4.protocol.txt MEDIUM: connection: Upstream SOCKS4 proxy support 2019-05-31 17:24:06 +02:00
SPOE.txt DOC: fix typos 2019-05-25 07:34:24 +02:00
WURFL-device-detection.txt DOC: fix typos 2019-05-25 07:34:24 +02:00