func (c *ProxyController) EditConditions(info *models.FormConditions) {
	rule := proxy.GetRule(info.Host, info.TargetURL)
	if rule == nil {
		c.Log().Errorf("Proxy rule not found for %#v", info)
		c.Reply().BadRequest().JSON(aah.Data{
			"message": "Proxy rule not found",
		})
		return
	}
	path := strings.TrimSpace(info.Path)
	if len(path) > 0 {
		rule.Path = path
	}
	var fieldErrors []*models.FieldError
	queryParams, errs := util.Lines2MapString(info.QueryParams, "=", false)
	if len(errs) > 0 {
		c.Log().Errorf("Proxy conditions error on Query Param values %s", strings.Join(errs, ", "))
		fieldErrors = append(fieldErrors, &models.FieldError{
			Name:    "queryParams",
			Message: "Query params has invalid values: \n" + strings.Join(errs, "\n"),
		})
		c.Reply().BadRequest().JSON(aah.Data{
			"message": "failed",
			"errors":  fieldErrors,
		})
		return
	}
	rule.QueryParams = queryParams
	headers, errs := util.Lines2MapString(info.Headers, "=", true)
	if len(errs) > 0 {
		c.Log().Errorf("Proxy conditions error on Header values %s", strings.Join(errs, ", "))
		fieldErrors = append(fieldErrors, &models.FieldError{
			Name:    "headers",
			Message: "Headers has invalid values: \n" + strings.Join(errs, "\n"),
		})
		c.Reply().BadRequest().JSON(aah.Data{
			"message": "failed",
			"errors":  fieldErrors,
		})
		return
	}
	rule.Headers = headers
	c.updateRule("EditConditions", info.TargetURL, rule)
}
EditConditions method handles Conditions values of proxy rule.
package admin
import (
	"strings"
	"thumbai/app/datastore"
	"thumbai/app/models"
	"thumbai/app/proxy"
	"thumbai/app/util"
	"aahframe.work"
	"aahframe.work/essentials"
)
type ProxyController struct {
	BaseController
}
func (c *ProxyController) List() {
	c.Reply().HTML(aah.Data{
		"IsProxy":    true,
		"AllProxies": proxy.All(),
	})
}
func (c *ProxyController) Show(hostName string) {
	proxyRules := proxy.Get(hostName)
	c.Reply().HTML(aah.Data{
		"IsProxy":       true,
		"ProxyHostName": hostName,
		"ProxyRules":    proxyRules,
	})
}
func (c *ProxyController) AddRulePage(hostName string) {
	c.Reply().HTMLf("edit.html", aah.Data{
		"IsProxy": true,
		"Rule":    &models.ProxyRule{Host: hostName},
	})
}
func (c *ProxyController) EditRulePage(hostName, targetURL string) {
	rule := proxy.GetRule(hostName, targetURL)
	c.Reply().HTMLf("edit.html", aah.Data{
		"IsProxy":  true,
		"EditRule": true,
		"Rule":     rule,
	})
}
func (c *ProxyController) Hosts() {
	c.Reply().JSON(aah.Data{
		"hosts": proxy.All(),
	})
}
func (c *ProxyController) Host(hostName string) {
	rules := proxy.Get(hostName)
	c.Reply().JSON(aah.Data{
		"proxy_rules": rules,
	})
}
func (c *ProxyController) AddHost(proxyInfo *models.FormTargetURL) {
	var fieldErrors []*models.FieldError
	if err := proxy.AddHost(proxyInfo); err != nil {
		switch {
		case err == datastore.ErrRecordAlreadyExists:
			fieldErrors = append(fieldErrors, &models.FieldError{
				Name:    "hostName",
				Message: "Proxy host already exists",
			})
			c.Reply().BadRequest().JSON(aah.Data{
				"message": "failed",
				"errors":  fieldErrors,
			})
			return
		}
		c.Log().Error(err)
		c.Reply().InternalServerError().JSON(aah.Data{
			"message": "failed",
		})
		return
	}
	c.Reply().JSON(aah.Data{
		"message": "success",
	})
}
func (c *ProxyController) DelHost(hostName string) {
	if err := proxy.DelHost(hostName); err != nil {
		c.Log().Error(err)
		c.Reply().InternalServerError().JSON(aah.Data{
			"message": "failed",
		})
		return
	}
	c.Reply().NoContent()
	go proxy.Thumbai.DelHost(hostName)
}
func (c *ProxyController) DelProxyRule(hostName, targetURL string) {
	if err := proxy.DelRule(hostName, targetURL); err != nil {
		c.Log().Error("Unexpected error during delete rule %v", err)
	}
	proxy.Thumbai.DeleteRule(hostName, targetURL)
	c.Reply().NoContent()
}
func (c *ProxyController) EditTargetURL(info *models.FormTargetURL) {
	if ess.IsStrEmpty(info.OldTargetURL) {
		if err := proxy.AddRule(&models.ProxyRule{
			Host:          info.Host,
			TargetURL:     info.TargetURL,
			Last:          info.Last,
			SkipTLSVerify: info.SkipTLSVerify,
		}); err != nil {
			c.Log().Errorf("Unable to added new proxy rule '%s' for %#v", err, info)
			c.Reply().InternalServerError().JSON(aah.Data{
				"message": "Unable to add new proxy rule!",
			})
			return
		}
		c.Reply().JSON(aah.Data{
			"message": "success",
		})
		return
	}
	rule := proxy.GetRule(info.Host, info.OldTargetURL)
	if rule == nil {
		c.Log().Errorf("Proxy rule not found for %#v", info)
		c.Reply().BadRequest().JSON(aah.Data{
			"message": "Proxy rule not found",
		})
		return
	}
	rule.TargetURL = info.TargetURL
	rule.Last = info.Last
	rule.SkipTLSVerify = info.SkipTLSVerify
	c.updateRule("EditTargetURL", info.OldTargetURL, rule)
}