-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Strange behavior with groups + mw #96
Comments
Yes, it's still there.
|
This is because Group is relying on unreliable behavior in append. When a new group is created, it makes a copy of the parent echo; this is a shallow copy, though, so g.echo.middleware still points to the parent middleware. That's fine if you don't add any new middleware. If you do, though, then it's dependent on whether or not the slice has capacity for the new middleware. If it doesn't, then append grows the slice and returns a new pointer to the larger slice, which contains all the parent middleware and the new middleware; this is fine. If you're unlucky and there's enough capacity, it just adds the new middleware to the slice, affecting both the parent echo and any other groups that are pointing at it. A cheap fix is to just copy over the parent middleware into a new slice the first time you call Use() on Group. This got it working again for me. However, there are other ways that yield different results; for example, Group might keep its own mw list without copying, but then always iterate over the parent middleware before its own (or vice versa, as the case may be). This would allow you to add middleware to the parent echo after creating the group, which may be more like expected behavior. |
I have several groups and some groups use specific middlewares.
But I noticed that in some combination of mw some groups start using middlewares from another groups.
For example:
files:
code:
So, if you open http://127.0.0.1:8085/static/test.txt
You'll see "Admin" in console. It means that /static/test.txt use another middleware which is in "/admin" group.
But if I remove e.Use(mw.Recover()) or e.Use(mw.Gzip()) everything works ok.
It's really odd.
The text was updated successfully, but these errors were encountered: