mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-23 17:20:24 +08:00
chore: update unauthorized callback calling order (#1469)
* chore: update unauthorized callback calling order * chore: add comments
This commit is contained in:
parent
df0f8ed59e
commit
fdc7f64d6f
@ -112,7 +112,8 @@ func (lim *TokenLimiter) reserveN(now time.Time, n int) bool {
|
|||||||
// Lua boolean false -> r Nil bulk reply
|
// Lua boolean false -> r Nil bulk reply
|
||||||
if err == redis.Nil {
|
if err == redis.Nil {
|
||||||
return false
|
return false
|
||||||
} else if err != nil {
|
}
|
||||||
|
if err != nil {
|
||||||
logx.Errorf("fail to use rate limiter: %s, use in-process limiter for rescue", err)
|
logx.Errorf("fail to use rate limiter: %s, use in-process limiter for rescue", err)
|
||||||
lim.startMonitor()
|
lim.startMonitor()
|
||||||
return lim.rescueLimiter.AllowN(now, n)
|
return lim.rescueLimiter.AllowN(now, n)
|
||||||
|
@ -742,7 +742,9 @@ func getValueWithChainedKeys(m Valuer, keys []string) (interface{}, bool) {
|
|||||||
if len(keys) == 1 {
|
if len(keys) == 1 {
|
||||||
v, ok := m.Value(keys[0])
|
v, ok := m.Value(keys[0])
|
||||||
return v, ok
|
return v, ok
|
||||||
} else if len(keys) > 1 {
|
}
|
||||||
|
|
||||||
|
if len(keys) > 1 {
|
||||||
if v, ok := m.Value(keys[0]); ok {
|
if v, ok := m.Value(keys[0]); ok {
|
||||||
if nextm, ok := v.(map[string]interface{}); ok {
|
if nextm, ok := v.(map[string]interface{}); ok {
|
||||||
return getValueWithChainedKeys(MapValuer(nextm), keys[1:])
|
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)
|
detailAuthLog(r, noDetailReason)
|
||||||
}
|
}
|
||||||
|
|
||||||
writer.WriteHeader(http.StatusUnauthorized)
|
// let callback go first, to make sure we respond with user-defined HTTP header
|
||||||
|
|
||||||
if callback != nil {
|
if callback != nil {
|
||||||
callback(writer, r, err)
|
callback(writer, r, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if user not setting HTTP header, we set header with 401
|
||||||
|
writer.WriteHeader(http.StatusUnauthorized)
|
||||||
}
|
}
|
||||||
|
|
||||||
type guardedResponseWriter struct {
|
type guardedResponseWriter struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user