From 13ca05b5948f6c811e71a1bd98e98da06e1956bf Mon Sep 17 00:00:00 2001 From: zhangxu Date: Wed, 26 Jun 2019 09:58:37 +0800 Subject: [PATCH] disable the JS plugin by default --- cmd/proxy/proxy.go | 2 ++ pkg/plugin/engine.go | 20 ++++++++++++++++++-- pkg/proxy/proxy.go | 2 +- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/cmd/proxy/proxy.go b/cmd/proxy/proxy.go index 21834cff..166f6c09 100644 --- a/cmd/proxy/proxy.go +++ b/cmd/proxy/proxy.go @@ -69,6 +69,7 @@ var ( // enable features enableWebSocket = flag.Bool("websocket", false, "enable websocket") + enableJSPlugin = flag.Bool("js", false, "enable js plugin") ) func init() { @@ -169,6 +170,7 @@ func getCfg() *proxy.Cfg { cfg.Option.LimitIntervalHeathCheck = time.Second * time.Duration(*limitIntervalHeathCheckSec) cfg.Option.JWTCfgFile = *jwtCfg cfg.Option.EnableWebSocket = *enableWebSocket + cfg.Option.EnableJSPlugin = *enableJSPlugin specs := defaultFilters if len(*filters) > 0 { diff --git a/pkg/plugin/engine.go b/pkg/plugin/engine.go index 4cf65b69..8b22caab 100644 --- a/pkg/plugin/engine.go +++ b/pkg/plugin/engine.go @@ -14,13 +14,16 @@ import ( type Engine struct { filter.BaseFilter + enable bool applied []*Runtime lastActive time.Time } // NewEngine returns a plugin engine -func NewEngine() *Engine { - return &Engine{} +func NewEngine(enable bool) *Engine { + return &Engine{ + enable: enable, + } } // LastActive returns the time that last used @@ -91,6 +94,10 @@ func (eng *Engine) Init(cfg string) error { // Pre filter pre method func (eng *Engine) Pre(c filter.Context) (int, error) { + if !eng.enable { + return eng.BaseFilter.Pre(c) + } + eng.lastActive = time.Now() if len(eng.applied) == 0 { @@ -118,6 +125,10 @@ func (eng *Engine) Pre(c filter.Context) (int, error) { // Post filter post method func (eng *Engine) Post(c filter.Context) (int, error) { + if !eng.enable { + return eng.BaseFilter.Post(c) + } + eng.lastActive = time.Now() if len(eng.applied) == 0 { @@ -149,6 +160,11 @@ func (eng *Engine) Post(c filter.Context) (int, error) { // PostErr filter post error method func (eng *Engine) PostErr(c filter.Context, code int, err error) { + if !eng.enable { + eng.BaseFilter.PostErr(c, code, err) + return + } + eng.lastActive = time.Now() if len(eng.applied) == 0 { diff --git a/pkg/proxy/proxy.go b/pkg/proxy/proxy.go index de565d48..92b9dc73 100644 --- a/pkg/proxy/proxy.go +++ b/pkg/proxy/proxy.go @@ -89,7 +89,7 @@ func NewProxy(cfg *Cfg) *Proxy { dispatches: make([]chan *dispatchNode, cfg.Option.LimitCountDispatchWorker, cfg.Option.LimitCountDispatchWorker), dispatchIndex: 0, copyIndex: 0, - jsEngine: plugin.NewEngine(), + jsEngine: plugin.NewEngine(cfg.Option.EnableJSPlugin), } p.init()