Skip to content

Commit

Permalink
BUG/MINOR: compression direction both not supported
Browse files Browse the repository at this point in the history
  • Loading branch information
hdurand0710 committed Feb 20, 2024
1 parent fd6b9e5 commit 2ab7c3b
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 7 deletions.
25 changes: 25 additions & 0 deletions configuration/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -1190,6 +1190,15 @@ func (s *SectionParser) compression() interface{} {
}
}

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

if compressionFound {
return compression
}
Expand Down Expand Up @@ -2624,6 +2633,16 @@ func (s *SectionObject) compression(field reflect.Value) error {
if err != nil {
return err
}

err = s.set("compression direction", nil)
if err != nil {
// compression direction does not exist on Frontends
var setErr error
if errors.As(parser_errors.ErrAttributeNotFound, &setErr) {
return nil
}
return err
}
return nil
}
compression, ok := field.Elem().Interface().(models.Compression)
Expand All @@ -2649,6 +2668,12 @@ func (s *SectionObject) compression(field reflect.Value) error {
return err
}
}
if len(compression.Direction) > 0 {
err = s.set("compression direction", &types.StringC{Value: compression.Direction})
if err != nil {
return err
}
}
return nil
}

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.0.1-0.20231205133436-67d880c8f163
github.com/haproxytech/config-parser/v5 v5.1.1-0.20240220100901-1145ec548975
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.0.1-0.20231205133436-67d880c8f163 h1:drZRX/gg1eUH3f4VkdjfEwfGqiDxJP0xvNQQt7FeHgc=
github.com/haproxytech/config-parser/v5 v5.0.1-0.20231205133436-67d880c8f163/go.mod h1:iy8nBB1eopwYbyeh3FQpjxZUxfcIDyTV9bW0F1t+cVA=
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/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
54 changes: 54 additions & 0 deletions models/compression.go

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

8 changes: 8 additions & 0 deletions models/compression_compare.go

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

4 changes: 2 additions & 2 deletions models/compression_compare_test.go

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

7 changes: 7 additions & 0 deletions specification/build/haproxy_spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9862,6 +9862,13 @@ definitions:
type: string
type: array
x-omitempty: true
direction:
enum:
- request
- response
- both
type: string
x-omitempty: true
offload:
type: boolean
types:
Expand Down
4 changes: 4 additions & 0 deletions specification/models/configuration/misc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,10 @@ compression:
type: string
offload:
type: boolean
direction:
type: string
enum: [request, response, both]
x-omitempty: true
stats_http_request:
type: object
required:
Expand Down
3 changes: 2 additions & 1 deletion test/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ func TestCreateEditDeleteBackend(t *testing.T) {
},
AcceptInvalidHTTPResponse: "enabled",
Compression: &models.Compression{
Offload: true,
Offload: true,
Direction: "both",
},
LogHealthChecks: "enabled",
Checkcache: "enabled",
Expand Down
1 change: 1 addition & 0 deletions test/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,7 @@ backend test
no option accept-invalid-http-response
no option h1-case-adjust-bogus-server
compression type application/json text/plain
compression direction both
srvtcpka-cnt 10
srvtcpka-idle 10s
srvtcpka-intvl 10
Expand Down
3 changes: 2 additions & 1 deletion test/expected/structured.json
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,8 @@
"types": [
"application/json",
"text/plain"
]
],
"direction": "both"
},
"cookie": {
"httponly": true,
Expand Down

0 comments on commit 2ab7c3b

Please sign in to comment.