diff --git a/plugins/limit_count_redis/filter.go b/plugins/limit_count_redis/filter.go index 6dd563b8..b019dced 100644 --- a/plugins/limit_count_redis/filter.go +++ b/plugins/limit_count_redis/filter.go @@ -149,13 +149,12 @@ func (f *filter) EncodeHeaders(headers api.ResponseHeaderMap, endStream bool) ap } // According to the RFC, these headers MUST NOT occur multiple times. - headers.Add("x-ratelimit-limit", fmt.Sprintf("%d, %s", minCount, config.quotaPolicy)) + headers.Set("x-ratelimit-limit", fmt.Sprintf("%d, %s", minCount, config.quotaPolicy)) if minRemain <= 0 { - headers.Add("x-ratelimit-remaining", "0") + headers.Set("x-ratelimit-remaining", "0") } else { - headers.Add("x-ratelimit-remaining", strconv.FormatInt(minRemain, 10)) + headers.Set("x-ratelimit-remaining", strconv.FormatInt(minRemain, 10)) } - headers.Add("x-ratelimit-remaining", strconv.FormatInt(minRemain, 10)) - headers.Add("x-ratelimit-reset", strconv.FormatInt(minTTL, 10)) + headers.Set("x-ratelimit-reset", strconv.FormatInt(minTTL, 10)) return api.Continue } diff --git a/plugins/tests/integration/limit_count_redis_test.go b/plugins/tests/integration/limit_count_redis_test.go index 54487b4b..7319f2a9 100644 --- a/plugins/tests/integration/limit_count_redis_test.go +++ b/plugins/tests/integration/limit_count_redis_test.go @@ -127,9 +127,9 @@ func TestLimitCountRedis(t *testing.T) { hdr.Add("x-key", "1") resp, _ := dp.Head("/echo", hdr) assert.Equal(t, 200, resp.StatusCode) - assert.Equal(t, "1, 1;w=1", resp.Header.Get("X-Ratelimit-Limit")) - assert.Equal(t, "0", resp.Header.Get("X-Ratelimit-Remaining")) - assert.Equal(t, "1", resp.Header.Get("X-Ratelimit-Reset")) + assert.Equal(t, []string{"1, 1;w=1"}, resp.Header.Values("X-Ratelimit-Limit")) + assert.Equal(t, []string{"0"}, resp.Header.Values("X-Ratelimit-Remaining")) + assert.Equal(t, []string{"1"}, resp.Header.Values("X-Ratelimit-Reset")) resp, _ = dp.Head("/echo", hdr) assert.Equal(t, 429, resp.StatusCode) assert.Equal(t, "1, 1;w=1", resp.Header.Get("X-Ratelimit-Limit")) @@ -163,9 +163,9 @@ func TestLimitCountRedis(t *testing.T) { hdr.Add("x-key", "1") resp, _ := dp.Head("/echo", hdr) assert.Equal(t, 200, resp.StatusCode) - assert.Equal(t, "2, 2;w=10, 2;w=1, 3;w=1", resp.Header.Get("X-Ratelimit-Limit")) - assert.Equal(t, "1", resp.Header.Get("X-Ratelimit-Remaining")) - assert.Equal(t, "10", resp.Header.Get("X-Ratelimit-Reset")) + assert.Equal(t, []string{"2, 2;w=10, 2;w=1, 3;w=1"}, resp.Header.Values("X-Ratelimit-Limit")) + assert.Equal(t, []string{"1"}, resp.Header.Values("X-Ratelimit-Remaining")) + assert.Equal(t, []string{"10"}, resp.Header.Values("X-Ratelimit-Reset")) hdr2 := http.Header{} hdr2.Add("x-key", "2")