1
0
mirror of https://github.com/astaxie/beego.git synced 2024-12-22 08:40:50 +00:00

fix the filter router issues

This commit is contained in:
astaxie 2015-06-13 12:47:01 +08:00
parent 27b452cd95
commit e619d83990
2 changed files with 11 additions and 9 deletions

View File

@ -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
}

View File

@ -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)