e619d839 by astaxie

fix the filter router issues

1 parent 27b452cd
...@@ -611,19 +611,21 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) ...@@ -611,19 +611,21 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
611 if p.enableFilter { 611 if p.enableFilter {
612 if l, ok := p.filters[pos]; ok { 612 if l, ok := p.filters[pos]; ok {
613 for _, filterR := range l { 613 for _, filterR := range l {
614 if ok, p := filterR.ValidRouter(urlPath); ok { 614 if filterR.returnOnOutput && w.started {
615 for k, v := range p { 615 return true
616 }
617 if ok, params := filterR.ValidRouter(urlPath); ok {
618 for k, v := range params {
616 context.Input.Params[k] = v 619 context.Input.Params[k] = v
617 } 620 }
618 filterR.filterFunc(context) 621 filterR.filterFunc(context)
619 if filterR.returnOnOutput && w.started { 622 }
620 return true 623 if filterR.returnOnOutput && w.started {
621 } 624 return true
622 } 625 }
623 } 626 }
624 } 627 }
625 } 628 }
626
627 return false 629 return false
628 } 630 }
629 631
......
...@@ -444,7 +444,7 @@ func TestFilterAfterExec(t *testing.T) { ...@@ -444,7 +444,7 @@ func TestFilterAfterExec(t *testing.T) {
444 mux := NewControllerRegister() 444 mux := NewControllerRegister()
445 mux.InsertFilter(url, BeforeRouter, beegoFilterNoOutput) 445 mux.InsertFilter(url, BeforeRouter, beegoFilterNoOutput)
446 mux.InsertFilter(url, BeforeExec, beegoFilterNoOutput) 446 mux.InsertFilter(url, BeforeExec, beegoFilterNoOutput)
447 mux.InsertFilter(url, AfterExec, beegoAfterExec1) 447 mux.InsertFilter(url, AfterExec, beegoAfterExec1, false)
448 448
449 mux.Get(url, beegoFilterFunc) 449 mux.Get(url, beegoFilterFunc)
450 450
...@@ -506,7 +506,7 @@ func TestFilterFinishRouterMultiFirstOnly(t *testing.T) { ...@@ -506,7 +506,7 @@ func TestFilterFinishRouterMultiFirstOnly(t *testing.T) {
506 url := "/finishRouterMultiFirstOnly" 506 url := "/finishRouterMultiFirstOnly"
507 507
508 mux := NewControllerRegister() 508 mux := NewControllerRegister()
509 mux.InsertFilter(url, FinishRouter, beegoFinishRouter1) 509 mux.InsertFilter(url, FinishRouter, beegoFinishRouter1, false)
510 mux.InsertFilter(url, FinishRouter, beegoFinishRouter2) 510 mux.InsertFilter(url, FinishRouter, beegoFinishRouter2)
511 511
512 mux.Get(url, beegoFilterFunc) 512 mux.Get(url, beegoFilterFunc)
...@@ -534,7 +534,7 @@ func TestFilterFinishRouterMulti(t *testing.T) { ...@@ -534,7 +534,7 @@ func TestFilterFinishRouterMulti(t *testing.T) {
534 534
535 mux := NewControllerRegister() 535 mux := NewControllerRegister()
536 mux.InsertFilter(url, FinishRouter, beegoFinishRouter1, false) 536 mux.InsertFilter(url, FinishRouter, beegoFinishRouter1, false)
537 mux.InsertFilter(url, FinishRouter, beegoFinishRouter2) 537 mux.InsertFilter(url, FinishRouter, beegoFinishRouter2, false)
538 538
539 mux.Get(url, beegoFilterFunc) 539 mux.Get(url, beegoFilterFunc)
540 540
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!