mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 09:00:55 +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 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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user