mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-28 14:43:48 +03:00
basicauth: Simplify user replacement on auth failure (#2470)
* Can simply add user to replacer before Replace call. user is then also added to logs * use fmt.Errorf * fix how fmt.Errorf is called.
This commit is contained in:
parent
b295aab2d8
commit
4f8020a94c
1 changed files with 3 additions and 4 deletions
|
@ -106,10 +106,9 @@ func (a BasicAuth) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error
|
|||
|
||||
// Get a replacer so we can provide basic info for the authentication error.
|
||||
repl := httpserver.NewReplacer(r, nil, "-")
|
||||
errstr := repl.Replace("BasicAuth: user \"%s\" was not found or password was incorrect. {remote} {host} {uri} {proto}")
|
||||
|
||||
// Username will not exist in Replacer so provide here.
|
||||
err := fmt.Errorf(errstr, username)
|
||||
repl.Set("user", username)
|
||||
errstr := repl.Replace("BasicAuth: user \"{user}\" was not found or password was incorrect. {remote} {host} {uri} {proto}")
|
||||
err := fmt.Errorf("%s", errstr)
|
||||
return http.StatusUnauthorized, err
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue