From 74b6bef9df0b463d77b3436bca7c4a4618693eae Mon Sep 17 00:00:00 2001 From: Bel LaPointe <153096461+breel-render@users.noreply.github.com> Date: Wed, 9 Sep 2026 14:44:55 -0700 Subject: [PATCH] ifthen --- config.go | 6 ++++++ main.go | 18 +++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/config.go b/config.go index 55de8bd..da0293b 100644 --- a/config.go +++ b/config.go @@ -28,6 +28,12 @@ type ( To string Redir bool BasicAuth string `yaml:"basicAuth"` + If []IfThen + } + + IfThen struct { + Headers map[string]string + Then Endpoint } ) diff --git a/main.go b/main.go index f500faa..e7d5486 100644 --- a/main.go +++ b/main.go @@ -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 {