Echo: RemoveTrailingSlash doesn't do anything

Created on 8 Sep 2016  路  3Comments  路  Source: labstack/echo

Description

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.

Checklist

  • [x] Dependencies installed
  • [x] No typos
  • [x] Searched existing issues and docs

    Expected behaviour

Both GET /foo and GET /foo/ should result in HTTP 200 and be served by the HTTP handler.

Actual behaviour

A GET /foo/ results in HTTP 404.

Steps to reproduce

$ 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%                                                                                                             

Working code to debug

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"))
}

Version/commit

e980bd9

$ go version
go version go1.7.1 linux/amd64
invalid

Most helpful comment

I updated the README.md

All 3 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wangxianzhuo picture wangxianzhuo  路  4Comments

asdine picture asdine  路  3Comments

montanaflynn picture montanaflynn  路  3Comments

runner-mei picture runner-mei  路  4Comments

arun0009 picture arun0009  路  3Comments