Compare commits
2
Commits
052b00caae
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
28d6bca84a | ||
|
|
74b6bef9df |
@@ -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
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user