diff --git a/drivers/plugins/counter/executor.go b/drivers/plugins/counter/executor.go index 5efd9a2c..3f9a80b8 100644 --- a/drivers/plugins/counter/executor.go +++ b/drivers/plugins/counter/executor.go @@ -51,19 +51,19 @@ func (b *executor) DoHttpFilter(ctx http_service.IHttpContext, next eocontext.IC b.client = scope_manager.Auto[counter.IClient](b.clientID, "counter") b.counterPusher = scope_manager.Auto[counter.ICountPusher](b.countPusherID, "counter-pusher") }) - body := ctx.Response().GetBody() - if len(body) < 1 { + + variables, ok := b.keyGenerate.Variables(ctx) + if !ok { return next.DoChain(ctx) } - key := b.keyGenerate.Key(ctx) ct, has := b.counters.Get(key) if !has { switch b.countMode { case localMode: - ct = NewLocalCounter(key, b.keyGenerate.Variables(ctx), b.client, b.counterPusher) + ct = NewLocalCounter(key, variables, b.client, b.counterPusher) case redisMode: - ct = NewRedisCounter(key, b.keyGenerate.Variables(ctx), b.cache, b.client, b.counterPusher) + ct = NewRedisCounter(key, variables, b.cache, b.client, b.counterPusher) } b.counters.Set(key, ct) } diff --git a/drivers/plugins/counter/key.go b/drivers/plugins/counter/key.go index 807aed96..4ee9bbc5 100644 --- a/drivers/plugins/counter/key.go +++ b/drivers/plugins/counter/key.go @@ -13,7 +13,7 @@ var _ IKeyGenerator = (*keyGenerate)(nil) type IKeyGenerator interface { Key(ctx http_service.IHttpContext) string - Variables(ctx http_service.IHttpContext) eosc.Untyped[string, string] + Variables(ctx http_service.IHttpContext) (eosc.Untyped[string, string], bool) } func newKeyGenerate(key string) *keyGenerate { @@ -43,13 +43,17 @@ type keyGenerate struct { variables []string } -func (k *keyGenerate) Variables(ctx http_service.IHttpContext) eosc.Untyped[string, string] { +func (k *keyGenerate) Variables(ctx http_service.IHttpContext) (eosc.Untyped[string, string], bool) { variables := eosc.BuildUntyped[string, string]() entry := ctx.GetEntry() for _, v := range k.variables { - variables.Set(fmt.Sprintf("$%s", v), eosc.ReadStringFromEntry(entry, v)) + value := eosc.ReadStringFromEntry(entry, v) + if value == "" { + return nil, false + } + variables.Set(fmt.Sprintf("$%s", v), value) } - return variables + return variables, true } func (k *keyGenerate) Key(ctx http_service.IHttpContext) string {