From e619d839901efc0120af07e25c47eff8e824fc46 Mon Sep 17 00:00:00 2001 From: astaxie Date: Sat, 13 Jun 2015 12:47:01 +0800 Subject: [PATCH] fix the filter router issues --- router.go | 14 ++++++++------ router_test.go | 6 +++--- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/router.go b/router.go index 4d195bc8..ca6d917a 100644 --- a/router.go +++ b/router.go @@ -611,19 +611,21 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) if p.enableFilter { if l, ok := p.filters[pos]; ok { for _, filterR := range l { - if ok, p := filterR.ValidRouter(urlPath); ok { - for k, v := range p { + if filterR.returnOnOutput && w.started { + return true + } + if ok, params := filterR.ValidRouter(urlPath); ok { + for k, v := range params { context.Input.Params[k] = v } filterR.filterFunc(context) - if filterR.returnOnOutput && w.started { - return true - } + } + if filterR.returnOnOutput && w.started { + return true } } } } - return false } diff --git a/router_test.go b/router_test.go index ee712167..005f32d6 100644 --- a/router_test.go +++ b/router_test.go @@ -444,7 +444,7 @@ func TestFilterAfterExec(t *testing.T) { mux := NewControllerRegister() mux.InsertFilter(url, BeforeRouter, beegoFilterNoOutput) mux.InsertFilter(url, BeforeExec, beegoFilterNoOutput) - mux.InsertFilter(url, AfterExec, beegoAfterExec1) + mux.InsertFilter(url, AfterExec, beegoAfterExec1, false) mux.Get(url, beegoFilterFunc) @@ -506,7 +506,7 @@ func TestFilterFinishRouterMultiFirstOnly(t *testing.T) { url := "/finishRouterMultiFirstOnly" mux := NewControllerRegister() - mux.InsertFilter(url, FinishRouter, beegoFinishRouter1) + mux.InsertFilter(url, FinishRouter, beegoFinishRouter1, false) mux.InsertFilter(url, FinishRouter, beegoFinishRouter2) mux.Get(url, beegoFilterFunc) @@ -534,7 +534,7 @@ func TestFilterFinishRouterMulti(t *testing.T) { mux := NewControllerRegister() mux.InsertFilter(url, FinishRouter, beegoFinishRouter1, false) - mux.InsertFilter(url, FinishRouter, beegoFinishRouter2) + mux.InsertFilter(url, FinishRouter, beegoFinishRouter2, false) mux.Get(url, beegoFilterFunc)