]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: support for http-response set-timeout
authorVladimir Vdovin <deliran@verdict.gg>
Mon, 16 Oct 2023 14:09:13 +0000 (17:09 +0300)
committerWilly Tarreau <w@1wt.eu>
Tue, 17 Oct 2023 06:27:33 +0000 (08:27 +0200)
Added set-timeout action for http-response. Adapted reg-tests and
documentation.

doc/configuration.txt
reg-tests/http-set-timeout/set_timeout.vtc
src/http_act.c

index 0b74ae29158d5f1a1d3b7244dbc57e060ba294b8..88a576795b4094b824210d91f52388a76b8f3217 100644 (file)
@@ -8087,6 +8087,7 @@ http-response <action> <options...> [ { if | unless } <condition> ]
     - set-mark <mark>
     - set-nice <nice>
     - set-status <status> [reason <str>]
+    - set-timeout { client | server | tunnel } { <timeout> | <expr> }
     - set-tos <tos>
     - set-var(<var-name>[,<cond>...]) <expr>
     - set-var-fmt(<var-name>[,<cond>...]) <fmt>
@@ -8332,6 +8333,24 @@ http-response set-status <status> [reason <str>]
     # return "503 Slow Down", custom reason
     http-response set-status 503 reason "Slow Down".
 
+http-response set-timeout { client | server | tunnel } { <timeout> | <expr> }
+                                       [ { if | unless } <condition> ]
+
+  This action overrides the specified "client", "server" or "tunnel" timeout for the
+  current stream only. The timeout can be specified in millisecond or with any
+  other unit if the number is suffixed by the unit as explained at the top of
+  this document. It is also possible to write an expression which must returns
+  a number interpreted as a timeout in millisecond.
+
+  Note that the server/tunnel timeouts are only relevant on the backend side
+  and thus this rule is only available for the proxies with backend
+  capabilities. As well as client timeout is only relevant for frontend side.
+  Also the timeout value must be non-null to obtain the expected results.
+
+  Example:
+    http-response set-timeout tunnel 5s
+    http-response set-timeout server res.hdr(X-Refresh-Seconds),mul(1000)
+
 http-response set-tos <tos> [ { if | unless } <condition> ]
 
   This is used to set the TOS or DSCP field value of packets sent to the client
index 6fa0a35f115d2e49e65a74c26e3a57c63a16d551..a112bc51e0f9d9d64d068ae118dec9be6af69af9 100644 (file)
@@ -4,7 +4,7 @@ feature ignore_unknown_macro
 
 #REQUIRE_VERSION=2.4
 
-server srv_h1 -repeat 5 {
+server srv_h1 -repeat 9 {
     rxreq
     txresp
 } -start
@@ -34,6 +34,26 @@ syslog Slog5 -level info {
     expect ~ "^.*timeout: 5000 3000.*$"
 } -start
 
+syslog Slog6 -level info {
+    recv
+    expect ~ "^.*timeout: 5000 5000.*$"
+} -start
+
+syslog Slog7 -level info {
+    recv
+    expect ~ "^.*timeout: 5000 5000.*$"
+} -start
+
+syslog Slog8 -level info {
+    recv
+    expect ~ "^.*timeout: 5000 3000.*$"
+} -start
+
+syslog Slog9 -level info {
+    recv
+    expect ~ "^.*timeout: 5000 3000.*$"
+} -start
+
 haproxy hap -conf {
     defaults
         timeout connect 5s
@@ -87,6 +107,46 @@ haproxy hap -conf {
     backend be2
        mode http
        server srv_h1 ${srv_h1_addr}:${srv_h1_port}
+
+    listen li4
+        mode http
+        bind "fd@${li4}"
+        log-format "timeout: %[be_server_timeout] %[cur_server_timeout]"
+        log ${Slog6_addr}:${Slog6_port} len 2048 local0 debug err
+        http-response set-timeout server 5s
+       server srv_h1 ${srv_h1_addr}:${srv_h1_port}
+
+    listen li5
+        mode http
+        bind "fd@${li5}"
+        log-format "timeout: %[fe_client_timeout] %[cur_client_timeout]"
+        log ${Slog7_addr}:${Slog7_port} len 2048 local0 debug err
+        http-response set-timeout client 5s
+       server srv_h1 ${srv_h1_addr}:${srv_h1_port}
+
+    frontend fe3
+        mode http
+        bind "fd@${fe3}"
+        log-format "timeout: %[be_server_timeout] %[cur_server_timeout]"
+        log ${Slog8_addr}:${Slog8_port} len 2048 local0 debug err
+        default_backend be1
+
+    backend be3
+       mode http
+       http-response set-timeout server int(3),mul(1000)
+       server srv_h1 ${srv_h1_addr}:${srv_h1_port}
+
+    frontend fe4
+        mode http
+        bind "fd@${fe4}"
+        log-format "timeout: %[fe_client_timeout] %[cur_client_timeout]"
+        log ${Slog9_addr}:${Slog9_port} len 2048 local0 debug err
+        http-response set-timeout client int(3),mul(1000)
+        default_backend be2
+
+    backend be4
+       mode http
+       server srv_h1 ${srv_h1_addr}:${srv_h1_port}
 } -start
 
 client c1 -connect ${hap_li1_sock} {
@@ -119,8 +179,36 @@ client c5 -connect ${hap_fe2_sock} {
     expect resp.status == 200
 } -run
 
+client c6 -connect ${hap_li4_sock} {
+    txreq
+    rxresp
+    expect resp.status == 200
+} -run
+
+client c7 -connect ${hap_fe3_sock} {
+    txreq
+    rxresp
+    expect resp.status == 200
+} -run
+
+client c8 -connect ${hap_li5_sock} {
+    txreq
+    rxresp
+    expect resp.status == 200
+} -run
+
+client c9 -connect ${hap_fe4_sock} {
+    txreq
+    rxresp
+    expect resp.status == 200
+} -run
+
 syslog Slog1 -wait
 syslog Slog2 -wait
 syslog Slog3 -wait
 syslog Slog4 -wait
 syslog Slog5 -wait
+syslog Slog6 -wait
+syslog Slog7 -wait
+syslog Slog8 -wait
+syslog Slog9 -wait
index 1878b03dd92d0a15671aeaf4b59328605943a466..93df4f037c08c70c7aa94b56ca2d0db97a001f35 100644 (file)
@@ -2464,6 +2464,7 @@ static struct action_kw_list http_res_actions = {
                { "set-status",      parse_http_set_status,     0 },
                { "strict-mode",     parse_http_strict_mode,    0 },
                { "track-sc",        parse_http_track_sc,       KWF_MATCH_PREFIX },
+               { "set-timeout",     parse_http_set_timeout,    0 },
                { "wait-for-body",   parse_http_wait_for_body,  0 },
                { NULL, NULL }
        }