From 70d2d9aefcf5f79aedd8037f0e2675bfe863fb19 Mon Sep 17 00:00:00 2001 From: Vladimir Vdovin Date: Mon, 16 Oct 2023 17:09:13 +0300 Subject: [PATCH] MINOR: support for http-response set-timeout Added set-timeout action for http-response. Adapted reg-tests and documentation. --- doc/configuration.txt | 19 +++++ reg-tests/http-set-timeout/set_timeout.vtc | 90 +++++++++++++++++++++- src/http_act.c | 1 + 3 files changed, 109 insertions(+), 1 deletion(-) diff --git a/doc/configuration.txt b/doc/configuration.txt index 0b74ae291..88a576795 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -8087,6 +8087,7 @@ http-response [ { if | unless } ] - set-mark - set-nice - set-status [reason ] + - set-timeout { client | server | tunnel } { | } - set-tos - set-var([,...]) - set-var-fmt([,...]) @@ -8332,6 +8333,24 @@ http-response set-status [reason ] # return "503 Slow Down", custom reason http-response set-status 503 reason "Slow Down". +http-response set-timeout { client | server | tunnel } { | } + [ { if | unless } ] + + 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 [ { if | unless } ] This is used to set the TOS or DSCP field value of packets sent to the client diff --git a/reg-tests/http-set-timeout/set_timeout.vtc b/reg-tests/http-set-timeout/set_timeout.vtc index 6fa0a35f1..a112bc51e 100644 --- a/reg-tests/http-set-timeout/set_timeout.vtc +++ b/reg-tests/http-set-timeout/set_timeout.vtc @@ -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 diff --git a/src/http_act.c b/src/http_act.c index 1878b03dd..93df4f037 100644 --- a/src/http_act.c +++ b/src/http_act.c @@ -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 } }