From 5b0898c8e8608898fece2f0382b020ef0dcead71 Mon Sep 17 00:00:00 2001 From: Mygod Date: Sun, 5 Nov 2023 10:04:09 -0500 Subject: [PATCH] Remove useless field --- caddyfile.go | 1 - common_test.go | 4 ---- forwardproxy.go | 5 ++--- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/caddyfile.go b/caddyfile.go index 87dde9e..239b5c7 100644 --- a/caddyfile.go +++ b/caddyfile.go @@ -58,7 +58,6 @@ func (h *Handler) UnmarshalCaddyfile(d *caddyfile.Dispenser) error { h.AuthCredentials = [][]byte{} } h.AuthCredentials = append(h.AuthCredentials, EncodeAuthCredentials(args[0], args[1])) - h.AuthRequired = true case "hosts": if len(args) == 0 { return d.ArgErr() diff --git a/common_test.go b/common_test.go index 18ce832..4880d3b 100644 --- a/common_test.go +++ b/common_test.go @@ -204,7 +204,6 @@ func TestMain(m *testing.M) { PACPath: defaultPACPath, ACL: []ACLRule{{Subjects: []string{"all"}, Allow: true}}, AuthCredentials: [][]byte{EncodeAuthCredentials("test", "pass")}, - AuthRequired: true, }, } @@ -215,7 +214,6 @@ func TestMain(m *testing.M) { PACPath: defaultPACPath, ACL: []ACLRule{{Subjects: []string{"all"}, Allow: true}}, AuthCredentials: [][]byte{EncodeAuthCredentials("test", "pass")}, - AuthRequired: true, }, } @@ -228,7 +226,6 @@ func TestMain(m *testing.M) { ACL: []ACLRule{{Subjects: []string{"all"}, Allow: true}}, ProbeResistance: &ProbeResistance{Domain: "test.localhost"}, AuthCredentials: [][]byte{EncodeAuthCredentials("test", "pass")}, - AuthRequired: true, }, httpRedirPort: "8880", } @@ -257,7 +254,6 @@ func TestMain(m *testing.M) { proxyHandler: &Handler{ Upstream: "https://test:pass@127.0.0.1:4891", AuthCredentials: [][]byte{EncodeAuthCredentials("upstreamtest", "upstreampass")}, - AuthRequired: true, }, } diff --git a/forwardproxy.go b/forwardproxy.go index c2f4982..218f205 100644 --- a/forwardproxy.go +++ b/forwardproxy.go @@ -92,7 +92,6 @@ type Handler struct { aclRules []aclRule // TODO: temporary/deprecated - we should try to reuse existing authentication modules instead! - AuthRequired bool `json:"auth_required,omitempty"` AuthCredentials [][]byte `json:"auth_credentials,omitempty"` // slice with base64-encoded credentials } @@ -146,7 +145,7 @@ func (h *Handler) Provision(ctx caddy.Context) error { h.aclRules = append(h.aclRules, &aclAllRule{allow: true}) if h.ProbeResistance != nil { - if !h.AuthRequired { + if h.AuthCredentials == nil { return fmt.Errorf("probe resistance requires authentication") } if len(h.ProbeResistance.Domain) > 0 { @@ -228,7 +227,7 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyht } var authErr error - if h.AuthRequired { + if h.AuthCredentials != nil { authErr = h.checkCredentials(r) } if h.ProbeResistance != nil && len(h.ProbeResistance.Domain) > 0 && reqHost == h.ProbeResistance.Domain {