rpcperms: re-init mw lookup map after removal of one

After removing a registered middlware from the slice, we need to update
the index lookup map with the updated index for each middleware.
This commit is contained in:
Elle Mouton
2022-07-15 14:04:19 +02:00
parent af97b8f877
commit cc2fbd18b1
2 changed files with 10 additions and 0 deletions

View File

@@ -489,10 +489,17 @@ func (r *InterceptorChain) RemoveMiddleware(middlewareName string) {
return
}
delete(r.registeredMiddlewareNames, middlewareName)
r.registeredMiddleware = append(
r.registeredMiddleware[:index],
r.registeredMiddleware[index+1:]...,
)
// Re-initialise the middleware look-up map with the updated indexes.
r.registeredMiddlewareNames = make(map[string]int)
for i, mw := range r.registeredMiddleware {
r.registeredMiddlewareNames[mw.middlewareName] = i
}
}
// CustomCaveatSupported makes sure a middleware that handles the given custom