The RemoveTrailingSlash middleware does not appear to do what it is meant to do: remove trailing slashes from requests so that the request can be matched by HTTP handlers that omit the trailing slash.
Both GET /foo and GET /foo/ should result in HTTP 200 and be served by the HTTP handler.
A GET /foo/ results in HTTP 404.
$ go run slashtest.go
$ curl -i localhost:1323/foo
HTTP/1.1 200 OK
Content-Type: text/plain; charset=utf-8
Date: Wed, 07 Sep 2016 23:58:50 GMT
Content-Length: 13
Hello, World!%
$ curl -i localhost:1323/foo/
HTTP/1.1 404 Not Found
Content-Type: text/plain; charset=utf-8
Date: Wed, 07 Sep 2016 23:58:52 GMT
Content-Length: 9
Not Found%
package main
import (
"net/http"
"github.com/labstack/echo"
"github.com/labstack/echo/engine/standard"
"github.com/labstack/echo/middleware"
)
func main() {
e := echo.New()
e.Use(middleware.RemoveTrailingSlash())
e.GET("/foo", func(c echo.Context) error {
return c.String(http.StatusOK, "Hello, World!")
})
e.Run(standard.New(":1323"))
}
e980bd9
$ go version
go version go1.7.1 linux/amd64
From the docs https://echo.labstack.com/middleware/trailing-slash, it should be registered using e.Pre.
Thanks! Nice to see there is a way to register pre-routing middleware.
The README links to the trailing slash middleware documentation are currently 404. I ended up reading the test code and some old Google cached docs, which misled me.
I updated the README.md
Most helpful comment
I updated the
README.md