Skip to content

Commit 4953424

Browse files
committed
add comments
1 parent c14a570 commit 4953424

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

exceptbasicauth.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ func New(ctx context.Context, next http.Handler, config *Config, name string) (h
6565

6666
func (e *ExceptBasicAuth) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
6767
extractedIPs := e.extractIP(req)
68+
69+
// we "whitelist" the request (i.e. adding the pre-configured Auth header) on two rules
70+
// - either the remote ip is allowed
71+
// - or it contains a preconfigured, valid header
6872
if (len(extractedIPs) > 0 && e.isAnyIPAllowed(extractedIPs)) || e.hasValidHeader(req) {
6973
req.SetBasicAuth(e.config.User, e.config.Password)
7074
} else if e.config.PreventUser && req.Header.Get("Authorization") != "" {
@@ -95,6 +99,8 @@ func (e *ExceptBasicAuth) extractIP(req *http.Request) []string {
9599
}
96100

97101
if len(possibleIPs) < 1 {
102+
// fallback on req.RemoteAddr if no source header is configured
103+
// or could be found in the request
98104
ip, _, err := net.SplitHostPort(req.RemoteAddr)
99105
if err == nil {
100106
possibleIPs = append(possibleIPs, ip)

0 commit comments

Comments
 (0)