Skip to content

Commit

Permalink
BUG/MINOR: add compression algo-req algo-res type-req type-res
Browse files Browse the repository at this point in the history
  • Loading branch information
hdurand0710 committed Feb 21, 2024
1 parent 9d32b8b commit 82f886f
Show file tree
Hide file tree
Showing 11 changed files with 336 additions and 7 deletions.
30 changes: 30 additions & 0 deletions configuration/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,36 @@ func TestGetBackend(t *testing.T) {
if b.Compression.Direction != "both" {
t.Errorf("%v: Compression.Direction not both: %v", b.Name, b.Compression.Direction)
}
if b.Compression.AlgoReq != "raw-deflate" {
t.Errorf("%v: Compression.AlgoReq wrong: %v", b.Name, b.Compression.AlgoReq)
}
if len(b.Compression.AlgosRes) != 2 {
t.Errorf("%v: len Compression.AlgosRes not 2: %v", b.Name, len(b.Compression.AlgosRes))
} else {
if !(b.Compression.AlgosRes[0] == "identity" || b.Compression.AlgosRes[0] == "raw-deflate") {
t.Errorf("%v: Compression.AlgosRes[0] wrong: %v", b.Name, b.Compression.AlgosRes[0])
}
if !(b.Compression.AlgosRes[1] != "identity" || b.Compression.AlgosRes[0] == "raw-deflate") {
t.Errorf("%v: Compression.AlgosRes[1] wrong: %v", b.Name, b.Compression.AlgosRes[1])
}
}
if len(b.Compression.TypesReq) != 2 {
t.Errorf("%v: len Compression.TypesReq not 2: %v", b.Name, len(b.Compression.TypesReq))
} else {
if !(b.Compression.TypesReq[0] == "text/plain" || b.Compression.TypesReq[0] == "application/json") {
t.Errorf("%v: Compression.TypesReq[0] wrong: %v", b.Name, b.Compression.TypesReq[0])
}
if !(b.Compression.TypesReq[1] != "text/plain" || b.Compression.TypesReq[0] == "application/json") {
t.Errorf("%v: Compression.TypesReq[1] wrong: %v", b.Name, b.Compression.TypesReq[1])
}
}
if len(b.Compression.TypesRes) != 1 {
t.Errorf("%v: len Compression.TypesRes not 1: %v", b.Name, len(b.Compression.TypesRes))
} else {
if !(b.Compression.TypesReq[0] == "text/plain") {
t.Errorf("%v: Compression.TypesReq[0] wrong: %v", b.Name, b.Compression.TypesReq[0])
}
}
}
if b.Checkcache != "enabled" {
t.Errorf("%v: Checkcache not enabled: %v", b.Name, b.Checkcache)
Expand Down
80 changes: 78 additions & 2 deletions configuration/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -1146,7 +1146,7 @@ func (s *SectionParser) monitorFail() interface{} {
return nil
}

func (s *SectionParser) compression() interface{} {
func (s *SectionParser) compression() interface{} { //nolint:gocognit
compressionFound := false
compression := &models.Compression{}

Expand All @@ -1160,6 +1160,24 @@ func (s *SectionParser) compression() interface{} {
}
}

data, err = s.get("compression algo-req", false)
if err == nil {
d, ok := data.(*types.StringC)
if ok && d != nil {
compressionFound = true
compression.AlgoReq = d.Value
}
}

data, err = s.get("compression algo-res", false)
if err == nil {
d, ok := data.(*types.StringSliceC)
if ok && d != nil && len(d.Value) > 0 {
compressionFound = true
compression.AlgosRes = d.Value
}
}

data, err = s.get("compression type", false)
if err == nil {
d, ok := data.(*types.StringSliceC)
Expand All @@ -1169,6 +1187,24 @@ func (s *SectionParser) compression() interface{} {
}
}

data, err = s.get("compression type-req", false)
if err == nil {
d, ok := data.(*types.StringSliceC)
if ok && d != nil && len(d.Value) > 0 {
compressionFound = true
compression.TypesReq = d.Value
}
}

data, err = s.get("compression type-res", false)
if err == nil {
d, ok := data.(*types.StringSliceC)
if ok && d != nil && len(d.Value) > 0 {
compressionFound = true
compression.TypesRes = d.Value
}
}

data, err = s.get("compression offload", false)
if err == nil {
d, ok := data.(*types.Enabled)
Expand Down Expand Up @@ -2606,17 +2642,33 @@ func (s *SectionObject) statsOptions(field reflect.Value) error {
return s.set("stats", ss)
}

func (s *SectionObject) compression(field reflect.Value) error {
func (s *SectionObject) compression(field reflect.Value) error { //nolint:gocognit
var err error
if valueIsNil(field) {
err = s.set("compression algo", nil)
if err != nil {
return err
}
err = s.set("compression algo-req", nil)
if err != nil {
return err
}
err = s.set("compression algo-res", nil)
if err != nil {
return err
}
err = s.set("compression type", nil)
if err != nil {
return err
}
err = s.set("compression type-req", nil)
if err != nil {
return err
}
err = s.set("compression type-res", nil)
if err != nil {
return err
}
err = s.set("compression offload", nil)
if err != nil {
return err
Expand Down Expand Up @@ -2644,12 +2696,36 @@ func (s *SectionObject) compression(field reflect.Value) error {
return err
}
}
if len(compression.AlgoReq) > 0 {
err = s.set("compression algo-req", &types.StringC{Value: compression.AlgoReq})
if err != nil {
return err
}
}
if len(compression.AlgosRes) > 0 {
err = s.set("compression algo-res", &types.StringSliceC{Value: compression.AlgosRes})
if err != nil {
return err
}
}
if len(compression.Types) > 0 {
err = s.set("compression type", &types.StringSliceC{Value: compression.Types})
if err != nil {
return err
}
}
if len(compression.TypesReq) > 0 {
err = s.set("compression type-req", &types.StringSliceC{Value: compression.TypesReq})
if err != nil {
return err
}
}
if len(compression.TypesRes) > 0 {
err = s.set("compression type-res", &types.StringSliceC{Value: compression.TypesRes})
if err != nil {
return err
}
}
if compression.Offload {
err = s.set("compression offload", &types.Enabled{})
if err != nil {
Expand Down
8 changes: 8 additions & 0 deletions configuration/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,10 @@ frontend test
compression algo identity gzip
compression type text/plain
compression offload
compression algo-req raw-deflate
compression algo-res raw-deflate identity
compression type-req text/plain application/json
compression type-res text/plain
clitcpka-cnt 10
clitcpka-idle 10s
clitcpka-intvl 10
Expand Down Expand Up @@ -676,6 +680,10 @@ backend test
no option h1-case-adjust-bogus-server
compression type application/json text/plain
compression direction both
compression algo-req raw-deflate
compression algo-res raw-deflate identity
compression type-req text/plain application/json
compression type-res text/plain
srvtcpka-cnt 10
srvtcpka-idle 10s
srvtcpka-intvl 10
Expand Down
30 changes: 30 additions & 0 deletions configuration/frontend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,36 @@ func TestGetFrontend(t *testing.T) {
if !f.Compression.Offload {
t.Errorf("%v: Compression.Offload wrong: %v", f.Name, f.Compression.Offload)
}
if f.Compression.AlgoReq != "raw-deflate" {
t.Errorf("%v: Compression.AlgoReq wrong: %v", f.Name, f.Compression.AlgoReq)
}
if len(f.Compression.AlgosRes) != 2 {
t.Errorf("%v: len Compression.AlgosRes not 2: %v", f.Name, len(f.Compression.AlgosRes))
} else {
if !(f.Compression.AlgosRes[0] == "identity" || f.Compression.AlgosRes[0] == "raw-deflate") {
t.Errorf("%v: Compression.AlgosRes[0] wrong: %v", f.Name, f.Compression.AlgosRes[0])
}
if !(f.Compression.AlgosRes[1] != "identity" || f.Compression.AlgosRes[0] == "raw-deflate") {
t.Errorf("%v: Compression.AlgosRes[1] wrong: %v", f.Name, f.Compression.AlgosRes[1])
}
}
if len(f.Compression.TypesReq) != 2 {
t.Errorf("%v: len Compression.TypesReq not 2: %v", f.Name, len(f.Compression.TypesReq))
} else {
if !(f.Compression.TypesReq[0] == "text/plain" || f.Compression.TypesReq[0] == "application/json") {
t.Errorf("%v: Compression.TypesReq[0] wrong: %v", f.Name, f.Compression.TypesReq[0])
}
if !(f.Compression.TypesReq[1] != "text/plain" || f.Compression.TypesReq[0] == "application/json") {
t.Errorf("%v: Compression.TypesReq[1] wrong: %v", f.Name, f.Compression.TypesReq[1])
}
}
if len(f.Compression.TypesRes) != 1 {
t.Errorf("%v: len Compression.TypesRes not 1: %v", f.Name, len(f.Compression.TypesRes))
} else {
if !(f.Compression.TypesReq[0] == "text/plain") {
t.Errorf("%v: Compression.TypesReq[0] wrong: %v", f.Name, f.Compression.TypesReq[0])
}
}
}

if f.HTTPIgnoreProbes != "enabled" {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/google/go-cmp v0.6.0
github.com/google/renameio v1.0.1
github.com/google/uuid v1.6.0
github.com/haproxytech/config-parser/v5 v5.1.1-0.20240220100901-1145ec548975
github.com/haproxytech/config-parser/v5 v5.1.1-0.20240221073837-5b782186def2
github.com/json-iterator/go v1.1.12
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
github.com/mitchellh/mapstructure v1.5.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ github.com/google/renameio v1.0.1 h1:Lh/jXZmvZxb0BBeSY5VKEfidcbcbenKjZFzM/q0fSeU
github.com/google/renameio v1.0.1/go.mod h1:t/HQoYBZSsWSNK35C6CO/TpPLDVWvxOHboWUAweKUpk=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/haproxytech/config-parser/v5 v5.1.1-0.20240220100901-1145ec548975 h1:CL/3SEvayajAyRHHOmKLsqiwZ8SVwAstCbKEvuxNknI=
github.com/haproxytech/config-parser/v5 v5.1.1-0.20240220100901-1145ec548975/go.mod h1:iy8nBB1eopwYbyeh3FQpjxZUxfcIDyTV9bW0F1t+cVA=
github.com/haproxytech/config-parser/v5 v5.1.1-0.20240221073837-5b782186def2 h1:YXI/15X8xJPrnyO8brmiNaFhOD17Ib9nszHRrlEtuIw=
github.com/haproxytech/config-parser/v5 v5.1.1-0.20240221073837-5b782186def2/go.mod h1:iy8nBB1eopwYbyeh3FQpjxZUxfcIDyTV9bW0F1t+cVA=
github.com/haproxytech/go-logger v1.1.0 h1:HgGtYaI1ApkvbQdsm7f9AzQQoxTB7w37criTflh7IQE=
github.com/haproxytech/go-logger v1.1.0/go.mod h1:OekUd8HCb7ubxMplzHUPBTHNxZmddOWfOjWclZsqIeM=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
Expand Down
105 changes: 105 additions & 0 deletions models/compression.go

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

Loading

0 comments on commit 82f886f

Please sign in to comment.