chore: update unauthorized callback calling order (#1469)

* chore: update unauthorized callback calling order

* chore: add comments
master
Kevin Wan 3 years ago committed by GitHub
parent df0f8ed59e
commit fdc7f64d6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -112,7 +112,8 @@ func (lim *TokenLimiter) reserveN(now time.Time, n int) bool {
// Lua boolean false -> r Nil bulk reply
if err == redis.Nil {
return false
} else if err != nil {
}
if err != nil {
logx.Errorf("fail to use rate limiter: %s, use in-process limiter for rescue", err)
lim.startMonitor()
return lim.rescueLimiter.AllowN(now, n)

@ -742,7 +742,9 @@ func getValueWithChainedKeys(m Valuer, keys []string) (interface{}, bool) {
if len(keys) == 1 {
v, ok := m.Value(keys[0])
return v, ok
} else if len(keys) > 1 {
}
if len(keys) > 1 {
if v, ok := m.Value(keys[0]); ok {
if nextm, ok := v.(map[string]interface{}); ok {
return getValueWithChainedKeys(MapValuer(nextm), keys[1:])

@ -113,11 +113,13 @@ func unauthorized(w http.ResponseWriter, r *http.Request, err error, callback Un
detailAuthLog(r, noDetailReason)
}
writer.WriteHeader(http.StatusUnauthorized)
// let callback go first, to make sure we respond with user-defined HTTP header
if callback != nil {
callback(writer, r, err)
}
// if user not setting HTTP header, we set header with 401
writer.WriteHeader(http.StatusUnauthorized)
}
type guardedResponseWriter struct {

Loading…
Cancel
Save