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

fix: Unclear behaviour of * in routes #2657

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

iamgoroot
Copy link

This should hopefully bring more clarity into this issue #2619

Examples would explain this better so here's similar to one from discussion

func main() {
	handler := func(c echo.Context) error {
		fmt.Printf("%s\n", c.Path())
		return nil
	}

	e := echo.New()
	v2 := e.Group("/v2")

	v2.DELETE("/*/blobs/:digest", handler)
	v2.GET("/*/blobs/:digest", handler)
	v2.HEAD("/*/blobs/:digest", handler)

	v2.DELETE("/*/manifests/:ref", handler)
	v2.GET("/*/manifests/:ref", handler)
	v2.HEAD("/*/manifests/:ref", handler)
	v2.PUT("/*/manifests/:ref", handler)

	v2.GET("/*/tags/list", handler)     // one wildcard
	v2.GET("/*/*/tags/list", handler)   // two wildcards
	v2.GET("/*/*/tags/list2*", handler) // two wildcards and trailing one
	v2.GET("/*/*/tags/list2", handler)  // two wildcards with fixed ending that may conflict with previous route

	v2.GET("/*/blobs/uploads/:ref", handler)
	v2.PATCH("/*/blobs/uploads/:ref", handler)
	v2.POST("/*/blobs/uploads", handler)
	v2.PUT("/*/blobs/uploads/:ref", handler)

	v2.GET("", handler)
	err := e.Start(":8080")
	if err != nil {
		panic(err)
	}
}

Example curl calls that should match those routes:

curl -ik  http://localhost:8080/v2/wildcard1/tags/list
# Matches /*/tags/list

curl -ik  http://localhost:8080/v2/wildcard1/wildcard2/tags/list
# Matches /*/*/tags/list

curl -ik  http://localhost:8080/v2/wildcard1/wildcard2/tags/list2wildcard3
# Matches /*/*/tags/list2*

curl -ik  http://localhost:8080/v2/wildcard1/wildcard2/tags/list2
# Matches /*/*/tags/list2

This one doesn't match since you would need to register it as /*/*/*/tags/list and this probably better implemented as separate ** wildcard

curl -ik  http://localhost:8080/v2/wildcard1/wildcard2/nowildcard/tags/list
{"message":"Method Not Allowed"}

@iamgoroot iamgoroot marked this pull request as ready for review July 17, 2024 22:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant