Skip to content
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

Resubmit: Remove group.Use registering Any routes that break other routes #1728

Closed
wants to merge 2 commits into from

Conversation

segevfiner
Copy link
Contributor

This can be a breaking change if this behavior is somehow important to anyone.

Fixes #1657

Resubmit of #1674

@aldas
Copy link
Contributor

aldas commented Dec 29, 2020

There needs to be discussion before this is merged

This part

	// Allow all requests to reach the group as they might get dropped if router
	// doesn't find a match, making none of the group middleware process.
	g.Any("", NotFoundHandler)
	g.Any("/*", NotFoundHandler)

was there for a reason - middleware that is attached to group is expected to be fired (example #1701) even if there is no httphandler match within that group (for example to serve static files). Or to be specific - in routing sense/domain there is no such thing as group there is only route to agains URL is matched.
If group is created then previously automatically 2 any or match all http method routes were added to router so middleware would be executed.

Probably it was not expected that anyone wants to create multiple groups with same path but with different middleware.

One example/explanation why it is so #838 basically This is example of mixing API routes with serving static files i.e. /api/* is served by echo http handlers and anything else on that group ("" or /group) are served as static files through static middleware.

g.Use(middleware.Static(""))

g.GET("/api", func(c echo.Context) error {
	return c.String(200, "1")
})

Now @segevfiner #1657 problem is valid as those routes (/group and /group/*) that are created when group is created are unexpected when you have actually creating multiple groups with same path. Especially when you are not expecting middleware to be fired for no match on group.

but just removing any routes would break users static routes attached group.

actually workaround for

	g1 := e.Group("", middleware1())
	{
		g1.GET("", handler)
	}
	g2 := e.Group("", middleware2())
	{
		g2.POST("/other", handler)
	}

is same as creating slice for group middleware and attaching it as third parameter when attaching http handler to path

g1 := e.Group("/users")
authorizedMiddleware := []middleware{middleware1(),checkPermission()}
g1.POST("/:id", handler, authorizedMiddleware)
g1.GET("/", listHandler, authorizedMiddleware)

publicMiddleware := []middleware{middleware2()}
g1.GET("/other", handler, publicMiddleware)
g1.GET("/other/:id", handler2, publicMiddleware)

so not to break existing apps serving middleware when these 2 "" and /* routes are removed is maybe to register those routes when static middleware is added g.Use(middleware.Static("")). but I have no idea how to do this. Also we do not know if there are other use-cases for setups where users are expecting middleware to be fired when no http handler is matched

@stale
Copy link

stale bot commented Jun 26, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed within a month if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale Marked as stale for auto-closing label Jun 26, 2021
@aldas aldas linked an issue Sep 14, 2021 that may be closed by this pull request
3 tasks
@aldas aldas added the v5 label Sep 17, 2021
@stale stale bot removed the stale Marked as stale for auto-closing label Sep 17, 2021
@stale
Copy link

stale bot commented Jan 9, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed within a month if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale Marked as stale for auto-closing label Jan 9, 2022
@aldas
Copy link
Contributor

aldas commented Jan 9, 2022

I'll leave it closed. This is done in v5 proposal. See this discussion for details #2000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Marked as stale for auto-closing v5
Projects
None yet
2 participants