Skip to content

Commit

Permalink
disable the JS plugin by default
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangxu19830126 committed Jun 26, 2019
1 parent 7b32838 commit 13ca05b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
2 changes: 2 additions & 0 deletions cmd/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ var (

// enable features
enableWebSocket = flag.Bool("websocket", false, "enable websocket")
enableJSPlugin = flag.Bool("js", false, "enable js plugin")
)

func init() {
Expand Down Expand Up @@ -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 {
Expand Down
20 changes: 18 additions & 2 deletions pkg/plugin/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 13ca05b

Please sign in to comment.