Skip to content

Commit

Permalink
MINOR: configuration: add http-response set-timeout
Browse files Browse the repository at this point in the history
Also add client as a timeout type to http-request set-timeout
action.
  • Loading branch information
mjuraga committed Nov 29, 2023
1 parent dc3ee83 commit ef5be78
Show file tree
Hide file tree
Showing 11 changed files with 194 additions and 25 deletions.
4 changes: 4 additions & 0 deletions configuration/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ frontend test
http-request wait-for-body time 20s at-least 100k
http-request set-timeout server 20
http-request set-timeout tunnel 20
http-request set-timeout client 20
http-request set-bandwidth-limit my-limit limit 1m period 10s
http-request set-bandwidth-limit my-limit-reverse period 20s limit 2m
http-request set-bandwidth-limit my-limit-cond limit 3m if FALSE
Expand Down Expand Up @@ -442,6 +443,9 @@ frontend test
http-response track-sc1 src table tr1 if TRUE
http-response track-sc2 src table tr2 if TRUE
http-response track-sc5 src table test if TRUE
http-response set-timeout server 20
http-response set-timeout tunnel 20
http-response set-timeout client 20
http-after-response set-map(map.lst) %[src] %[res.hdr(X-Value)]
http-after-response del-map(map.lst) %[src] if FALSE
http-after-response del-acl(map.lst) %[src] if FALSE
Expand Down
34 changes: 22 additions & 12 deletions configuration/http_request_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ func TestGetHTTPRequestRules(t *testing.T) { //nolint:gocognit,gocyclo
t.Error(err.Error())
}

if len(hRules) != 46 {
t.Errorf("%v http request rules returned, expected 46", len(hRules))
if len(hRules) != 47 {
t.Errorf("%v http request rules returned, expected 47", len(hRules))
}

if v != version {
Expand Down Expand Up @@ -605,6 +605,16 @@ func TestGetHTTPRequestRules(t *testing.T) { //nolint:gocognit,gocyclo
t.Errorf("%v: Timeout not 20: %v", *r.Index, r.Timeout)
}
case 39:
if r.Type != "set-timeout" {
t.Errorf("%v: Type not set-timeout: %v", *r.Index, r.Type)
}
if r.TimeoutType != "client" {
t.Errorf("%v: TimeoutType not client: %v", *r.Index, r.TimeoutType)
}
if r.Timeout != "20" {
t.Errorf("%v: Timeout not 20: %v", *r.Index, r.Timeout)
}
case 40:
if r.Type != "set-bandwidth-limit" {
t.Errorf("%v: Type not set-bandwidth-limit: %v", *r.Index, r.Type)
}
Expand All @@ -617,7 +627,7 @@ func TestGetHTTPRequestRules(t *testing.T) { //nolint:gocognit,gocyclo
if r.BandwidthLimitPeriod != "10s" {
t.Errorf("%v: BandwidthLimitPeriod not 10s: %v", *r.Index, r.BandwidthLimitPeriod)
}
case 40:
case 41:
if r.Type != "set-bandwidth-limit" {
t.Errorf("%v: Type not set-bandwidth-limit: %v", *r.Index, r.Type)
}
Expand All @@ -630,7 +640,7 @@ func TestGetHTTPRequestRules(t *testing.T) { //nolint:gocognit,gocyclo
if r.BandwidthLimitPeriod != "20s" {
t.Errorf("%v: BandwidthLimitPeriod no 20s: %v", *r.Index, r.BandwidthLimitPeriod)
}
case 41:
case 42:
if r.Type != "set-bandwidth-limit" {
t.Errorf("%v: Type not set-bandwidth-limit: %v", *r.Index, r.Type)
}
Expand All @@ -649,7 +659,7 @@ func TestGetHTTPRequestRules(t *testing.T) { //nolint:gocognit,gocyclo
if r.CondTest != "FALSE" {
t.Errorf("%v: CondTest not FALSE: %v", *r.Index, r.CondTest)
}
case 42:
case 43:
if r.Type != "track-sc" {
t.Errorf("%v: Type not track-sc: %v", *r.Index, r.Type)
}
Expand All @@ -668,7 +678,7 @@ func TestGetHTTPRequestRules(t *testing.T) { //nolint:gocognit,gocyclo
if r.CondTest != "TRUE" {
t.Errorf("%v: CondTest not TRUE: %v", *r.Index, r.CondTest)
}
case 43:
case 44:
if r.Type != "track-sc" {
t.Errorf("%v: Type not track-sc: %v", *r.Index, r.Type)
}
Expand All @@ -687,7 +697,7 @@ func TestGetHTTPRequestRules(t *testing.T) { //nolint:gocognit,gocyclo
if r.CondTest != "TRUE" {
t.Errorf("%v: CondTest not TRUE: %v", *r.Index, r.CondTest)
}
case 44:
case 45:
if r.Type != "track-sc" {
t.Errorf("%v: Type not track-sc: %v", *r.Index, r.Type)
}
Expand All @@ -706,7 +716,7 @@ func TestGetHTTPRequestRules(t *testing.T) { //nolint:gocognit,gocyclo
if r.CondTest != "TRUE" {
t.Errorf("%v: CondTest not TRUE: %v", *r.Index, r.CondTest)
}
case 45:
case 46:
if r.Type != "track-sc" {
t.Errorf("%v: Type not track-sc: %v", *r.Index, r.Type)
}
Expand All @@ -726,7 +736,7 @@ func TestGetHTTPRequestRules(t *testing.T) { //nolint:gocognit,gocyclo
t.Errorf("%v: CondTest not TRUE: %v", *r.Index, r.CondTest)
}
default:
t.Errorf("Expect only http-request 0 to 42, %v found", *r.Index)
t.Errorf("Expect only http-request 0 to 46, %v found", *r.Index)
}
}

Expand Down Expand Up @@ -888,7 +898,7 @@ func TestCreateEditDeleteHTTPRequestRule(t *testing.T) {
}

// TestDeleteHTTPRequest
err = clientTest.DeleteHTTPRequestRule(46, "frontend", "test", "", version)
err = clientTest.DeleteHTTPRequestRule(47, "frontend", "test", "", version)
if err != nil {
t.Error(err.Error())
} else {
Expand All @@ -899,9 +909,9 @@ func TestCreateEditDeleteHTTPRequestRule(t *testing.T) {
t.Error("Version not incremented")
}

_, _, err = clientTest.GetHTTPRequestRule(46, "frontend", "test", "")
_, _, err = clientTest.GetHTTPRequestRule(47, "frontend", "test", "")
if err == nil {
t.Error("DeleteHTTPRequestRule failed, HTTP Request Rule 46 still exists")
t.Error("DeleteHTTPRequestRule failed, HTTP Request Rule 47 still exists")
}

err = clientTest.DeleteHTTPRequestRule(2, "backend", "test_2", "", version)
Expand Down
15 changes: 15 additions & 0 deletions configuration/http_response_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,14 @@ func ParseHTTPResponseRule(f types.Action) *models.HTTPResponseRule { //nolint:m
r.Status = status
}
return r
case *http_actions.SetTimeout:
return &models.HTTPResponseRule{
Type: models.HTTPResponseRuleTypeSetDashTimeout,
Timeout: v.Timeout,
TimeoutType: v.Type,
Cond: v.Cond,
CondTest: v.CondTest,
}
case *actions.SetTos:
return &models.HTTPResponseRule{
Type: "set-tos",
Expand Down Expand Up @@ -746,6 +754,13 @@ func SerializeHTTPResponseRule(f models.HTTPResponseRule) (rule types.Action, er
Cond: f.Cond,
CondTest: f.CondTest,
}
case "set-timeout":
rule = &http_actions.SetTimeout{
Timeout: f.Timeout,
Type: f.TimeoutType,
Cond: f.Cond,
CondTest: f.CondTest,
}
case "set-tos":
rule = &actions.SetTos{
Value: f.TosValue,
Expand Down
42 changes: 36 additions & 6 deletions configuration/http_response_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ func TestGetHTTPResponseRules(t *testing.T) { //nolint:gocognit,gocyclo
t.Error(err.Error())
}

if len(hRules) != 32 {
t.Errorf("%v http response rules returned, expected 32", len(hRules))
if len(hRules) != 35 {
t.Errorf("%v http response rules returned, expected 35", len(hRules))
}

if v != version {
Expand Down Expand Up @@ -529,8 +529,38 @@ func TestGetHTTPResponseRules(t *testing.T) { //nolint:gocognit,gocyclo
if r.CondTest != "TRUE" {
t.Errorf("%v: CondTest not TRUE: %v", *r.Index, r.CondTest)
}
case 32:
if r.Type != "set-timeout" {
t.Errorf("%v: Type not set-timeout: %v", *r.Index, r.Type)
}
if r.TimeoutType != "server" {
t.Errorf("%v: TimeoutType not server: %v", *r.Index, r.TimeoutType)
}
if r.Timeout != "20" {
t.Errorf("%v: Timeout not 20: %v", *r.Index, r.Timeout)
}
case 33:
if r.Type != "set-timeout" {
t.Errorf("%v: Type not set-timeout: %v", *r.Index, r.Type)
}
if r.TimeoutType != "tunnel" {
t.Errorf("%v: TimeoutType not tunnel: %v", *r.Index, r.TimeoutType)
}
if r.Timeout != "20" {
t.Errorf("%v: Timeout not 20: %v", *r.Index, r.Timeout)
}
case 34:
if r.Type != "set-timeout" {
t.Errorf("%v: Type not set-timeout: %v", *r.Index, r.Type)
}
if r.TimeoutType != "client" {
t.Errorf("%v: TimeoutType not client: %v", *r.Index, r.TimeoutType)
}
if r.Timeout != "20" {
t.Errorf("%v: Timeout not 20: %v", *r.Index, r.Timeout)
}
default:
t.Errorf("Expect only http-response 0 to 28, %v found", *r.Index)
t.Errorf("Expect only http-response 0 to 34, %v found", *r.Index)
}
}

Expand Down Expand Up @@ -649,7 +679,7 @@ func TestCreateEditDeleteHTTPResponseRule(t *testing.T) {
}

// TestDeleteHTTPResponse
err = clientTest.DeleteHTTPResponseRule(32, "frontend", "test", "", version)
err = clientTest.DeleteHTTPResponseRule(35, "frontend", "test", "", version)
if err != nil {
t.Error(err.Error())
} else {
Expand All @@ -660,9 +690,9 @@ func TestCreateEditDeleteHTTPResponseRule(t *testing.T) {
t.Error("Version not incremented")
}

_, _, err = clientTest.GetHTTPResponseRule(32, "frontend", "test", "")
_, _, err = clientTest.GetHTTPResponseRule(35, "frontend", "test", "")
if err == nil {
t.Error("DeleteHTTPResponseRule failed, HTTPResponse Rule 32 still exists")
t.Error("DeleteHTTPResponseRule failed, HTTPResponse Rule 35 still exists")
}

err = clientTest.DeleteHTTPResponseRule(2, "backend", "test_2", "", version)
Expand Down
7 changes: 5 additions & 2 deletions models/http_request_rule.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 61 additions & 2 deletions models/http_response_rule.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions models/http_response_rule_compare.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ef5be78

Please sign in to comment.