| 21 | } |
| 22 | |
| 23 | func requireBasicAuth(ctx context.Context, wr http.ResponseWriter, req *http.Request, hidden_domain string, next Auth) (string, bool) { |
| 24 | if hidden_domain != "" { |
| 25 | if matchHiddenDomain(req.URL.Host, hidden_domain) || |
| 26 | matchHiddenDomain(req.Host, hidden_domain) { |
| 27 | wr.Header().Set("Proxy-Authenticate", BASIC_REALM_MSG) |
| 28 | http.Error(wr, AUTH_REQUIRED_MSG, http.StatusProxyAuthRequired) |
| 29 | return "", false |
| 30 | } |
| 31 | |
| 32 | if next != nil { |
| 33 | return next.Validate(ctx, wr, req) |
| 34 | } |
| 35 | |
| 36 | http.Error(wr, BAD_REQ_MSG, http.StatusBadRequest) |
| 37 | return "", false |
| 38 | } |
| 39 | |
| 40 | if next != nil { |
| 41 | return next.Validate(ctx, wr, req) |
| 42 | } |
| 43 | |
| 44 | wr.Header().Set("Proxy-Authenticate", BASIC_REALM_MSG) |
| 45 | http.Error(wr, AUTH_REQUIRED_MSG, http.StatusProxyAuthRequired) |
| 46 | return "", false |
| 47 | } |
| 48 | |
| 49 | func tryValid(auth Auth, logger *clog.CondLogger, user, password, userAddr string) bool { |
| 50 | if auth == nil { |