mirror of
https://github.com/labstack/echo.git
synced 2024-11-28 08:38:39 +02:00
fix issue #1086
This commit is contained in:
parent
d79727cf89
commit
ee32e3e7fb
12
echo.go
12
echo.go
@ -558,13 +558,13 @@ func (e *Echo) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
c.Reset(r, w)
|
||||
|
||||
method := r.Method
|
||||
path := r.URL.RawPath
|
||||
if path == "" {
|
||||
path = r.URL.Path
|
||||
}
|
||||
h := NotFoundHandler
|
||||
|
||||
if e.premiddleware == nil {
|
||||
path := r.URL.RawPath
|
||||
if path == "" {
|
||||
path = r.URL.Path
|
||||
}
|
||||
e.router.Find(method, path, c)
|
||||
h = c.Handler()
|
||||
for i := len(e.middleware) - 1; i >= 0; i-- {
|
||||
@ -572,6 +572,10 @@ func (e *Echo) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
} else {
|
||||
h = func(c Context) error {
|
||||
path := r.URL.RawPath
|
||||
if path == "" {
|
||||
path = r.URL.Path
|
||||
}
|
||||
e.router.Find(method, path, c)
|
||||
h := c.Handler()
|
||||
for i := len(e.middleware) - 1; i >= 0; i-- {
|
||||
|
@ -33,3 +33,28 @@ func TestRewrite(t *testing.T) {
|
||||
e.ServeHTTP(rec, req)
|
||||
assert.Equal(t, "/user/jack/order/1", req.URL.Path)
|
||||
}
|
||||
|
||||
//Issue #1086
|
||||
func TestEchoRewritePreMiddleware(t *testing.T) {
|
||||
e := echo.New()
|
||||
r := e.Router()
|
||||
|
||||
// Rewrite old url to new one
|
||||
e.Pre(RewriteWithConfig(RewriteConfig{
|
||||
Rules: map[string]string{
|
||||
"/old": "/new",
|
||||
},
|
||||
}))
|
||||
|
||||
// Route
|
||||
r.Add(echo.GET, "/new", func(c echo.Context) error {
|
||||
return c.NoContent(200)
|
||||
return nil
|
||||
})
|
||||
|
||||
req := httptest.NewRequest(echo.GET, "/old", nil)
|
||||
rec := httptest.NewRecorder()
|
||||
e.ServeHTTP(rec, req)
|
||||
assert.Equal(t, "/new", req.URL.Path)
|
||||
assert.Equal(t, 200, rec.Code)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user