mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 14:40:57 +00:00
fix the filter router issues
This commit is contained in:
parent
27b452cd95
commit
e619d83990
10
router.go
10
router.go
@ -611,19 +611,21 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
|
|||||||
if p.enableFilter {
|
if p.enableFilter {
|
||||||
if l, ok := p.filters[pos]; ok {
|
if l, ok := p.filters[pos]; ok {
|
||||||
for _, filterR := range l {
|
for _, filterR := range l {
|
||||||
if ok, p := filterR.ValidRouter(urlPath); ok {
|
if filterR.returnOnOutput && w.started {
|
||||||
for k, v := range p {
|
return true
|
||||||
|
}
|
||||||
|
if ok, params := filterR.ValidRouter(urlPath); ok {
|
||||||
|
for k, v := range params {
|
||||||
context.Input.Params[k] = v
|
context.Input.Params[k] = v
|
||||||
}
|
}
|
||||||
filterR.filterFunc(context)
|
filterR.filterFunc(context)
|
||||||
|
}
|
||||||
if filterR.returnOnOutput && w.started {
|
if filterR.returnOnOutput && w.started {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -444,7 +444,7 @@ func TestFilterAfterExec(t *testing.T) {
|
|||||||
mux := NewControllerRegister()
|
mux := NewControllerRegister()
|
||||||
mux.InsertFilter(url, BeforeRouter, beegoFilterNoOutput)
|
mux.InsertFilter(url, BeforeRouter, beegoFilterNoOutput)
|
||||||
mux.InsertFilter(url, BeforeExec, beegoFilterNoOutput)
|
mux.InsertFilter(url, BeforeExec, beegoFilterNoOutput)
|
||||||
mux.InsertFilter(url, AfterExec, beegoAfterExec1)
|
mux.InsertFilter(url, AfterExec, beegoAfterExec1, false)
|
||||||
|
|
||||||
mux.Get(url, beegoFilterFunc)
|
mux.Get(url, beegoFilterFunc)
|
||||||
|
|
||||||
@ -506,7 +506,7 @@ func TestFilterFinishRouterMultiFirstOnly(t *testing.T) {
|
|||||||
url := "/finishRouterMultiFirstOnly"
|
url := "/finishRouterMultiFirstOnly"
|
||||||
|
|
||||||
mux := NewControllerRegister()
|
mux := NewControllerRegister()
|
||||||
mux.InsertFilter(url, FinishRouter, beegoFinishRouter1)
|
mux.InsertFilter(url, FinishRouter, beegoFinishRouter1, false)
|
||||||
mux.InsertFilter(url, FinishRouter, beegoFinishRouter2)
|
mux.InsertFilter(url, FinishRouter, beegoFinishRouter2)
|
||||||
|
|
||||||
mux.Get(url, beegoFilterFunc)
|
mux.Get(url, beegoFilterFunc)
|
||||||
@ -534,7 +534,7 @@ func TestFilterFinishRouterMulti(t *testing.T) {
|
|||||||
|
|
||||||
mux := NewControllerRegister()
|
mux := NewControllerRegister()
|
||||||
mux.InsertFilter(url, FinishRouter, beegoFinishRouter1, false)
|
mux.InsertFilter(url, FinishRouter, beegoFinishRouter1, false)
|
||||||
mux.InsertFilter(url, FinishRouter, beegoFinishRouter2)
|
mux.InsertFilter(url, FinishRouter, beegoFinishRouter2, false)
|
||||||
|
|
||||||
mux.Get(url, beegoFilterFunc)
|
mux.Get(url, beegoFilterFunc)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user