Skip to content

Commit

Permalink
MINOR: remove deprecated in the spec
Browse files Browse the repository at this point in the history
  • Loading branch information
hdurand0710 authored and mjuraga committed Apr 19, 2024
1 parent 39daea7 commit b4ef162
Show file tree
Hide file tree
Showing 29 changed files with 10 additions and 1,358 deletions.
73 changes: 0 additions & 73 deletions configuration/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -1478,11 +1478,6 @@ type SectionObject struct {
Parser parser.Parser
Section parser.Section
Name string
// In the context of the deprecation of the fields:
// HTTPKeepAlive, HTTPServerClose and Httpclose.
// This flag is used to set a priority on HTTPConnectionMode field over
// the deprecated ones.
httpConnectionModeFlag bool
}

// CreateEditSection creates or updates a section in the parser based on the provided object
Expand All @@ -1493,7 +1488,6 @@ func CreateEditSection(object interface{}, section parser.Section, pName string,
Name: pName,
Parser: p,
}
so.setHTTPConnectionModeFlag()
return so.CreateEditSection()
}

Expand Down Expand Up @@ -1596,11 +1590,6 @@ func (s *SectionObject) checkSpecialFields(fieldName string, field reflect.Value
case "DefaultBackend":
return true, s.defaultBackend(field)
case "HTTPConnectionMode":
// if HTTPConnectionMode is not set, skip HTTPConnectionMode
// Write only options (Httpclose, HTTPKeepAlive, HTTPServerClose)
if !s.httpConnectionModeFlag {
return true, nil
}
return true, s.httpConnectionMode(field)
case "HTTPReuse":
return true, s.httpReuse(field)
Expand Down Expand Up @@ -1671,70 +1660,8 @@ func (s *SectionObject) checkTimeouts(fieldName string, field reflect.Value) (ma
return false, nil
}

// setHTTPConnectionModeFlag set the httpConnectionModeFlag flag if:
//
// HTTPConnectionMode is present, false otherwise.
//
// This check is needed due to the deprecation of deprecated options:
//
// HTTPKeepAlive, HTTPServerClose and Httpclose.
func (s *SectionObject) setHTTPConnectionModeFlag() {
objValue := reflect.ValueOf(s.Object)
if objValue.Kind() == reflect.Ptr {
objValue = reflect.ValueOf(s.Object).Elem()
}

deprecatedFieldPresent := false
atLeastOneDeprecatedFieldNotEmpty := false
httpConnectionModePresentSet := false
for i := 0; i < objValue.NumField(); i++ {
typeField := objValue.Type().Field(i)
field := objValue.FieldByName(typeField.Name)
if typeField.Name == "HTTPConnectionMode" && !valueIsNil(field) {
httpConnectionModePresentSet = true
}
if typeField.Name == "HTTPKeepAlive" || typeField.Name == "HTTPServerClose" || typeField.Name == "Httpclose" {
deprecatedFieldPresent = true
if !valueIsNil(field) {
atLeastOneDeprecatedFieldNotEmpty = true
}
}
}
// Backend
if deprecatedFieldPresent {
// if HTTPConnectionMode is present is not empty => has priority
if httpConnectionModePresentSet {
s.httpConnectionModeFlag = true
return
}

s.httpConnectionModeFlag = !atLeastOneDeprecatedFieldNotEmpty
return
}
// For Default and Frontend,
// HTTPKeepAlive, HTTPServerClose and Httpclose do not exist in the Object
// We are always using HTTPConnectionMode
s.httpConnectionModeFlag = true
}

// isHTTPConnectionModeDeprecatedField returns, in regards to the deprecation of HTTPConectionMode option fields:
//
// HTTPKeepAlive, HTTPServerClose and Httpclose.
//
// - true if it's a deprecated field, false otherwise
func isHTTPConnectionModeDeprecatedField(fieldName string) bool {
if fieldName == "HTTPKeepAlive" || fieldName == "HTTPServerClose" || fieldName == "Httpclose" {
return true
}
return false
}

func (s *SectionObject) checkOptions(fieldName string, field reflect.Value) (match bool, err error) {
if pName := fmt.Sprintf("option %s", misc.DashCase(fieldName)); s.Parser.HasParser(s.Section, pName) {
// Skip this field if it's a deprecated one and HTTPConnectionMode is present
if isHTTPConnectionModeDeprecatedField(fieldName) && s.httpConnectionModeFlag {
return true, nil
}
if valueIsNil(field) {
if err := s.set(pName, nil); err != nil {
return true, err
Expand Down
16 changes: 0 additions & 16 deletions configuration/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -1141,12 +1141,6 @@ func ParseGlobalSection(p parser.Parser) (*models.Global, error) { //nolint:goco
return nil, err
}

// deprecated option
dhParam := int64(0)
if tuneOptions != nil {
dhParam = tuneOptions.SslDefaultDhParam
}

global := &models.Global{
Anonkey: anonkey,
PresetEnvs: presetEnvs,
Expand Down Expand Up @@ -1197,7 +1191,6 @@ func ParseGlobalSection(p parser.Parser) (*models.Global, error) { //nolint:goco
SslProviderPath: sslProviderPath,
SslSkipSelfIssuedCa: sslSkipSelfIssuedCa,
TuneOptions: tuneOptions,
TuneSslDefaultDhParam: dhParam,
ExternalCheck: externalCheck,
LuaLoads: luaLoads,
LuaPrependPath: luaPrependPath,
Expand Down Expand Up @@ -2267,15 +2260,6 @@ func SerializeGlobalSection(p parser.Parser, data *models.Global) error { //noli
return err
}

// deprecated option
if data.TuneSslDefaultDhParam != 0 {
if data.TuneOptions != nil && data.TuneOptions.SslDefaultDhParam == 0 {
data.TuneOptions.SslDefaultDhParam = data.TuneSslDefaultDhParam
}
if data.TuneOptions == nil {
data.TuneOptions = &models.GlobalTuneOptions{SslDefaultDhParam: data.TuneSslDefaultDhParam}
}
}
return serializeTuneOptions(p, data.TuneOptions)
}

Expand Down
27 changes: 0 additions & 27 deletions configuration/http_request_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -1182,33 +1182,6 @@ func SerializeHTTPRequestRule(f models.HTTPRequestRule) (rule types.Action, err
Cond: f.Cond,
CondTest: f.CondTest,
}
case "track-sc0":
rule = &actions.TrackSc{
Type: actions.TrackScType,
StickCounter: 0,
Key: f.TrackSc0Key,
Table: f.TrackSc0Table,
Cond: f.Cond,
CondTest: f.CondTest,
}
case "track-sc1":
rule = &actions.TrackSc{
Type: actions.TrackScType,
StickCounter: 1,
Key: f.TrackSc1Key,
Table: f.TrackSc1Table,
Cond: f.Cond,
CondTest: f.CondTest,
}
case "track-sc2":
rule = &actions.TrackSc{
Type: actions.TrackScType,
StickCounter: 2,
Key: f.TrackSc2Key,
Table: f.TrackSc2Table,
Cond: f.Cond,
CondTest: f.CondTest,
}
case "track-sc":
if f.TrackScStickCounter == nil {
return nil, NewConfError(ErrValidationError, "track_sc_stick_counter must be set")
Expand Down
27 changes: 0 additions & 27 deletions configuration/http_response_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -840,33 +840,6 @@ func SerializeHTTPResponseRule(f models.HTTPResponseRule) (rule types.Action, er
Cond: f.Cond,
CondTest: f.CondTest,
}
case "track-sc0":
rule = &actions.TrackSc{
Type: actions.TrackScType,
StickCounter: 0,
Key: f.TrackSc0Key,
Table: f.TrackSc0Table,
Cond: f.Cond,
CondTest: f.CondTest,
}
case "track-sc1":
rule = &actions.TrackSc{
Type: actions.TrackScType,
StickCounter: 1,
Key: f.TrackSc1Key,
Table: f.TrackSc1Table,
Cond: f.Cond,
CondTest: f.CondTest,
}
case "track-sc2":
rule = &actions.TrackSc{
Type: actions.TrackScType,
StickCounter: 2,
Key: f.TrackSc2Key,
Table: f.TrackSc2Table,
Cond: f.Cond,
CondTest: f.CondTest,
}
case "track-sc":
if f.TrackScStickCounter == nil {
return nil, NewConfError(ErrValidationError, "track_sc_stick_counter must be set")
Expand Down
Loading

0 comments on commit b4ef162

Please sign in to comment.