Compare commits

..
2 Commits
Author SHA1 Message Date
Bel LaPointe 28d6bca84a ifthen help 2026-09-09 14:45:32 -07:00
Bel LaPointe 74b6bef9df ifthen 2026-09-09 14:44:55 -07:00
2 changed files with 24 additions and 2 deletions
+7 -1
View File
@@ -28,6 +28,12 @@ type (
To string
Redir bool
BasicAuth string `yaml:"basicAuth"`
If []IfThen
}
IfThen struct {
Headers map[string]string
Then Endpoint
}
)
@@ -38,7 +44,7 @@ func NewConfig() (*Config, error) {
fs.StringVar(&c.Cert.CRT, "crt", "", "path to .crt")
fs.StringVar(&c.Cert.Key, "key", "", "path to .key")
fs.IntVar(&c.Port, "p", 56112, "port to listen on")
f := fs.String("f", "/dev/null", `file of {domains:{.google.com:{mail:{to: scheme://host:port, basicAuth: u:p, redir: false}}}}`)
f := fs.String("f", "/dev/null", `file of {domains:{.google.com:{mail:{to: scheme://host:port, basicAuth: u:p, redir: false, if:{headers:{k:v}, then:{to:...}}}}}}`)
if err := fs.Parse(os.Args[1:]); err != nil {
return c, err
}
+17 -1
View File
@@ -160,7 +160,23 @@ func (c *Config) endpoint(r *http.Request) Endpoint {
if !ok {
return Endpoint{}
}
return m[key]
endpoint, ok := m[key]
if !ok {
return Endpoint{}
}
for _, iffer := range endpoint.If {
matches := true
for k, v := range iffer.Headers {
matches = matches && r.Header.Get(k) == v
}
if matches {
return iffer.Then
}
}
return endpoint
}
type redirPurge struct {