You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Chi middleware wrapping logic executes the beginning middlewares at the later part #687
changed the title [-]Chi middleware looping logic execute the beginning middlewares at the later part[/-][+]Chi middleware looping logic executes the beginning middlewares at the later part[/+]on Jul 20, 2022
changed the title [-]Chi middleware looping logic executes the beginning middlewares at the later part[/-][+]Chi middleware wrarping logic executes the beginning middlewares at the later part[/+]on Jul 20, 2022
changed the title [-]Chi middleware wrarping logic executes the beginning middlewares at the later part[/-][+]Chi middleware wrapping logic executes the beginning middlewares at the later part[/+]on Jul 20, 2022
// chain builds a http.Handler composed of an inline middleware stack and endpoint// handler in the order they are passed.funcchain(middlewares []func(http.Handler) http.Handler, endpoint http.Handler) http.Handler {
// Return ahead of time if there aren't any middlewares for the chainiflen(middlewares) ==0 {
returnendpoint
}
// Wrap the end handler with the middleware chainh:=middlewares[len(middlewares)-1](endpoint)
fori:=len(middlewares) -2; i>=0; i-- {
h=middlewares[i](h)
}
returnh
}
This has been fixed via the compatibility.apply-chi-middleware-first-to-last configuration option, which reverses the middleware wrapping order so that middlewares execute in the order they are listed. Closing as resolved.
Activity
[-]Chi middleware looping logic execute the beginning middlewares at the later part[/-][+]Chi middleware looping logic executes the beginning middlewares at the later part[/+][-]Chi middleware looping logic executes the beginning middlewares at the later part[/-][+]Chi middleware wrarping logic executes the beginning middlewares at the later part[/+][-]Chi middleware wrarping logic executes the beginning middlewares at the later part[/-][+]Chi middleware wrapping logic executes the beginning middlewares at the later part[/+]chanced commentedon Aug 5, 2022
Here is the source from chi:
https://github.com/go-chi/chi/blob/9db25e5b381fbd6350583b857e74ecaffe355819/chain.go#L34-L49
jazware commentedon Oct 22, 2022
This should now be supported in the next release (including this PR) using the following options in your config YAML:
This issue can be closed (but I don't have permissions to close it).
mromaszewicz commentedon Feb 7, 2026
This has been fixed via the compatibility.apply-chi-middleware-first-to-last configuration option, which reverses the middleware wrapping order so that middlewares execute in the order they are listed. Closing as resolved.