diff --git a/configuration/backend_test.go b/configuration/backend_test.go index 67036dbb..e21d50c2 100644 --- a/configuration/backend_test.go +++ b/configuration/backend_test.go @@ -373,6 +373,9 @@ func TestGetBackend(t *testing.T) { t.Errorf("%v: Compression.Types[1] wrong: %v", b.Name, b.Compression.Types[1]) } } + if b.Compression.Direction != "both" { + t.Errorf("%v: Compression.Direction not both: %v", b.Name, b.Compression.Direction) + } } if b.Checkcache != "enabled" { t.Errorf("%v: Checkcache not enabled: %v", b.Name, b.Checkcache) @@ -716,7 +719,8 @@ func TestCreateEditDeleteBackend(t *testing.T) { }, AcceptInvalidHTTPResponse: "enabled", Compression: &models.Compression{ - Offload: true, + Offload: true, + Direction: "both", }, LogHealthChecks: "enabled", Checkcache: "enabled", diff --git a/configuration/configuration.go b/configuration/configuration.go index 96aef06d..ad71b790 100644 --- a/configuration/configuration.go +++ b/configuration/configuration.go @@ -1172,6 +1172,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 } @@ -2600,6 +2609,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) @@ -2625,6 +2644,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 } diff --git a/configuration/configuration_test.go b/configuration/configuration_test.go index d7b405d1..9f92560d 100644 --- a/configuration/configuration_test.go +++ b/configuration/configuration_test.go @@ -643,6 +643,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 diff --git a/go.mod b/go.mod index c3cb86a2..e008256e 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,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.20230821131853-5878ad7f5340 + github.com/haproxytech/config-parser/v5 v5.1.1-0.20240220100901-1145ec548975 github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 github.com/mitchellh/mapstructure v1.5.0 github.com/pkg/errors v0.9.1 diff --git a/go.sum b/go.sum index 9e8c6923..3dcbbf30 100644 --- a/go.sum +++ b/go.sum @@ -30,8 +30,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.20230821131853-5878ad7f5340 h1:VtRnT4x7Cds0TxZCqDYFTyCnFMyJJA5FC+uRum+CUD4= -github.com/haproxytech/config-parser/v5 v5.0.1-0.20230821131853-5878ad7f5340/go.mod h1:cGtFso7oMTY1GIixWv9JG7pKSdyyacpWqNE7XPx6+mU= +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= diff --git a/models/compression.go b/models/compression.go index ee34e05e..895dbd41 100644 --- a/models/compression.go +++ b/models/compression.go @@ -39,6 +39,10 @@ type Compression struct { // algorithms Algorithms []string `json:"algorithms,omitempty"` + // direction + // Enum: [request response both] + Direction string `json:"direction,omitempty"` + // offload Offload bool `json:"offload,omitempty"` @@ -54,6 +58,10 @@ func (m *Compression) Validate(formats strfmt.Registry) error { res = append(res, err) } + if err := m.validateDirection(formats); err != nil { + res = append(res, err) + } + if len(res) > 0 { return errors.CompositeValidationError(res...) } @@ -96,6 +104,51 @@ func (m *Compression) validateAlgorithms(formats strfmt.Registry) error { return nil } +var compressionTypeDirectionPropEnum []interface{} + +func init() { + var res []string + if err := json.Unmarshal([]byte(`["request","response","both"]`), &res); err != nil { + panic(err) + } + for _, v := range res { + compressionTypeDirectionPropEnum = append(compressionTypeDirectionPropEnum, v) + } +} + +const ( + + // CompressionDirectionRequest captures enum value "request" + CompressionDirectionRequest string = "request" + + // CompressionDirectionResponse captures enum value "response" + CompressionDirectionResponse string = "response" + + // CompressionDirectionBoth captures enum value "both" + CompressionDirectionBoth string = "both" +) + +// prop value enum +func (m *Compression) validateDirectionEnum(path, location string, value string) error { + if err := validate.EnumCase(path, location, value, compressionTypeDirectionPropEnum, true); err != nil { + return err + } + return nil +} + +func (m *Compression) validateDirection(formats strfmt.Registry) error { + if swag.IsZero(m.Direction) { // not required + return nil + } + + // value enum + if err := m.validateDirectionEnum("direction", "body", m.Direction); err != nil { + return err + } + + return nil +} + // ContextValidate validates this compression based on context it is used func (m *Compression) ContextValidate(ctx context.Context, formats strfmt.Registry) error { return nil diff --git a/specification/build/haproxy_spec.yaml b/specification/build/haproxy_spec.yaml index d0fe2d8d..a0d58451 100644 --- a/specification/build/haproxy_spec.yaml +++ b/specification/build/haproxy_spec.yaml @@ -9636,6 +9636,13 @@ definitions: type: string type: array x-omitempty: true + direction: + enum: + - request + - response + - both + type: string + x-omitempty: true offload: type: boolean types: diff --git a/specification/models/configuration/misc.yaml b/specification/models/configuration/misc.yaml index 13e125e5..b2144f33 100644 --- a/specification/models/configuration/misc.yaml +++ b/specification/models/configuration/misc.yaml @@ -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: