Fix static path matching issue in macaron

This commit is contained in:
Kevin Minehart
2021-09-17 09:21:18 -05:00
committed by dsotirakis
parent c725a4259a
commit 2d456a6375
2 changed files with 15 additions and 4 deletions
+9
View File
@@ -146,6 +146,9 @@ func CreateDashboardSnapshot(c *models.ReqContext, cmd models.CreateDashboardSna
// GET /api/snapshots/:key
func GetDashboardSnapshot(c *models.ReqContext) response.Response {
key := c.Params(":key")
if len(key) == 0 {
return response.Error(404, "Snapshot not found", nil)
}
query := &models.GetDashboardSnapshotQuery{Key: key}
err := bus.Dispatch(query)
@@ -215,6 +218,9 @@ func deleteExternalDashboardSnapshot(externalUrl string) error {
// GET /api/snapshots-delete/:deleteKey
func DeleteDashboardSnapshotByDeleteKey(c *models.ReqContext) response.Response {
key := c.Params(":deleteKey")
if len(key) == 0 {
return response.Error(404, "Snapshot not found", nil)
}
query := &models.GetDashboardSnapshotQuery{DeleteKey: key}
@@ -245,6 +251,9 @@ func DeleteDashboardSnapshotByDeleteKey(c *models.ReqContext) response.Response
// DELETE /api/snapshots/:key
func DeleteDashboardSnapshot(c *models.ReqContext) response.Response {
key := c.Params(":key")
if len(key) == 0 {
return response.Error(404, "Snapshot not found", nil)
}
query := &models.GetDashboardSnapshotQuery{Key: key}
+6 -4
View File
@@ -289,10 +289,12 @@ func (r *Router) SetHandlerWrapper(f func(Handler) Handler) {
func (r *Router) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
if t, ok := r.routers[req.Method]; ok {
// Fast match for static routes
leaf := r.getLeaf(req.Method, req.URL.Path)
if leaf != nil {
leaf.handle(rw, req, nil)
return
if !strings.ContainsAny(req.URL.Path, ":*") {
leaf := r.getLeaf(req.Method, req.URL.Path)
if leaf != nil {
leaf.handle(rw, req, nil)
return
}
}
h, p, ok := t.Match(req.URL.EscapedPath())