Skip to content

Commit 9a6dbff

Browse files
committed
support option pause for http-request and http-response keywords
Signed-off-by: Vincent Gramer <vgramer@haproxy.com>
1 parent d1176cf commit 9a6dbff

22 files changed

Lines changed: 537 additions & 99 deletions
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
Copyright 2025 HAProxy Technologies
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package actions
18+
19+
import (
20+
stderrors "errors"
21+
"strings"
22+
23+
"github.com/haproxytech/client-native/v6/config-parser/common"
24+
"github.com/haproxytech/client-native/v6/config-parser/errors"
25+
"github.com/haproxytech/client-native/v6/config-parser/types"
26+
)
27+
28+
type Pause struct {
29+
Pause common.Expression
30+
Cond string
31+
CondTest string
32+
Comment string
33+
}
34+
35+
func (f *Pause) Parse(parts []string, parserType types.ParserType, comment string) error {
36+
if comment != "" {
37+
f.Comment = comment
38+
}
39+
if len(parts) >= 3 {
40+
command, condition := common.SplitRequest(parts[2:])
41+
if len(command) == 0 {
42+
return errors.ErrInvalidData
43+
}
44+
pauseExpr := common.Expression{}
45+
if err := pauseExpr.Parse(command); err != nil {
46+
return stderrors.New("not enough params")
47+
}
48+
f.Pause = pauseExpr
49+
if len(condition) > 1 {
50+
f.Cond = condition[0]
51+
f.CondTest = strings.Join(condition[1:], " ")
52+
}
53+
return nil
54+
}
55+
return stderrors.New("not enough params")
56+
}
57+
58+
func (f *Pause) String() string {
59+
var result strings.Builder
60+
result.WriteString("pause ")
61+
result.WriteString(f.Pause.String())
62+
if f.Cond != "" {
63+
result.WriteString(" ")
64+
result.WriteString(f.Cond)
65+
result.WriteString(" ")
66+
result.WriteString(f.CondTest)
67+
}
68+
return result.String()
69+
}
70+
71+
func (f *Pause) GetComment() string {
72+
return f.Comment
73+
}

config-parser/parsers/http/http-request.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ func (h *Requests) Parse(line string, parts []string, comment string) (string, e
7171
err = h.ParseHTTPRequest(&httpActions.EarlyHint{}, parts, comment)
7272
case "normalize-uri":
7373
err = h.ParseHTTPRequest(&httpActions.NormalizeURI{}, parts, comment)
74+
case "pause":
75+
err = h.ParseHTTPRequest(&httpActions.Pause{}, parts, comment)
7476
case "redirect":
7577
err = h.ParseHTTPRequest(&httpActions.Redirect{}, parts, comment)
7678
case "reject":

config-parser/parsers/http/http-response.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ func (h *Responses) Parse(line string, parts []string, comment string) (string,
6363
err = h.ParseHTTPResponse(&httpActions.DelHeader{}, parts, comment)
6464
case "deny":
6565
err = h.ParseHTTPResponse(&httpActions.Deny{}, parts, comment)
66+
case "pause":
67+
err = h.ParseHTTPResponse(&httpActions.Pause{}, parts, comment)
6668
case "redirect":
6769
err = h.ParseHTTPResponse(&httpActions.Redirect{}, parts, comment)
6870
case "replace-header":

config-parser/tests/configs/haproxy_generated.cfg.go

Lines changed: 60 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)