Skip to content

Routing Behaviour #954

@gambol99

Description

@gambol99

Description

The route doesn't appear to fallback into alternative routes. Using the following routes

e.Match(allHTTPMethods, "/api/v0/events/123456789", emptyHandler, contextMiddleware())
e.Match(allHTTPMethods, "/api/v0/events/404", emptyHandler, contextMiddleware())
e.Match(allHTTPMethods, "/api/v0/audit/*", emptyHandler, contextMiddleware())
e.Match(allHTTPMethods, "/*", emptyHandler, contextMiddleware())

Expected behaviour

you would expect /api/v0/events/1000 would be caught by /*, instead the route is never matched and thus handler and middleware never called. Indeed if I as to call /api/v0 it hits but v0/aq does not

[jest@starfury issue]$ curl http://127.0.0.1:1323/api/v0/ev/type
{"message":"Not Found"}
[jest@starfury issue]$ curl http://127.0.0.1:1323/api/v0
{"message":"Forbidden"}
[jest@starfury issue]$ curl http://127.0.0.1:1323/api/v0/aq
{"message":"Not Found"}

Steps to reproduce

Taking at the below snippet of code

package main

import (
	"fmt"

	"github.com/labstack/echo"
	"github.com/labstack/echo/middleware"
)

var (
	allHTTPMethods = []string{echo.DELETE, echo.GET, echo.HEAD, echo.OPTIONS, echo.PATCH, echo.POST, echo.PUT, echo.TRACE}
)

func main() {
	e := echo.New()
	// Middleware
	e.Use(middleware.Recover())
	e.Use(middleware.Logger())
	e.Match(allHTTPMethods, "/api/v0/events/123456789", emptyHandler, contextMiddleware())
	e.Match(allHTTPMethods, "/api/v0/events/404", emptyHandler, contextMiddleware())
	e.Match(allHTTPMethods, "/api/v0/audit/*", emptyHandler, contextMiddleware())
	e.Match(allHTTPMethods, "/*", emptyHandler, contextMiddleware())
	e.Use(proxyMiddleware())
	e.Logger.Fatal(e.Start(":1323"))
}

func emptyHandler(cx echo.Context) error {
	return nil
}

func proxyMiddleware() echo.MiddlewareFunc {
	return func(next echo.HandlerFunc) echo.HandlerFunc {
		return func(cx echo.Context) error {
			fmt.Println("CALLED PROXY")
			return next(cx)
		}
	}
}

func contextMiddleware() echo.MiddlewareFunc {
	return func(next echo.HandlerFunc) echo.HandlerFunc {
		return func(cx echo.Context) error {
			fmt.Println("CALLED MIDDLEWARE")
			return echo.ErrForbidden
		}
	}
}
[jest@starfury issue]$ curl http://127.0.0.1:1323/api/v0/events/123456789
{"message":"Forbidden"}
[jest@starfury issue]$ curl http://127.0.0.1:1323/api/v0/events/404
{"message":"Forbidden"}
# should be caught by by the /*
[jest@starfury issue]$ curl http://127.0.0.1:1323/api/v0/events/401
{"message":"Not Found"}
# should be caught by the /*
[jest@starfury issue]$ curl http://127.0.0.1:1323/api/v0/events/test/me
{"message":"Not Found"}
[jest@starfury issue]$ curl http://127.0.0.1:1323/api/v0/eventx/
{"message":"Not Found"}
⇨ http server started on [::]:1323
^[[ACALLED PROXY
CALLED MIDDLEWARE
{"time":"2017-06-14T21:35:54.882444977+01:00","id":"","remote_ip":"127.0.0.1","host":"127.0.0.1:1323","method":"GET","uri":"/api/v0/events/123456789","status":403, "latency":98717,"latency_human":"98.717µs","bytes_in":0,"bytes_out":23}
CALLED PROXY
CALLED MIDDLEWARE
{"time":"2017-06-14T21:36:04.113514471+01:00","id":"","remote_ip":"127.0.0.1","host":"127.0.0.1:1323","method":"GET","uri":"/api/v0/events/404","status":403, "latency":150316,"latency_human":"150.316µs","bytes_in":0,"bytes_out":23}
CALLED PROXY
{"time":"2017-06-14T21:36:06.535061149+01:00","id":"","remote_ip":"127.0.0.1","host":"127.0.0.1:1323","method":"GET","uri":"/api/v0/events/401","status":404, "latency":167137,"latency_human":"167.137µs","bytes_in":0,"bytes_out":23}
CALLED PROXY
{"time":"2017-06-14T21:36:11.883863283+01:00","id":"","remote_ip":"127.0.0.1","host":"127.0.0.1:1323","method":"GET","uri":"/api/v0/events/test/me","status":404, "latency":45823,"latency_human":"45.823µs","bytes_in":0,"bytes_out":23}
CALLED PROXY
{"time":"2017-06-14T21:40:42.994379375+01:00","id":"","remote_ip":"127.0.0.1","host":"127.0.0.1:1323","method":"GET","uri":"/api/v0/eventx/","status":404, "latency":31531,"latency_human":"31.531µs","bytes_in":0,"bytes_out":23}

Version/commit

[jest@starfury echo]$ git log -n1
commit 3fafadf (HEAD -> master, origin/master, origin/HEAD)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions