From 250d5f70a1aede29a3f46b3cac8ee003cdf9fcf2 Mon Sep 17 00:00:00 2001 From: Aapo Talvensaari Date: Tue, 13 Nov 2018 16:24:12 +0200 Subject: [PATCH] chore(response-ratelimiting) make plugin defensive against possible errors between the phases --- kong/plugins/response-ratelimiting/handler.lua | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/kong/plugins/response-ratelimiting/handler.lua b/kong/plugins/response-ratelimiting/handler.lua index 112313b7ed54..581979bf127b 100644 --- a/kong/plugins/response-ratelimiting/handler.lua +++ b/kong/plugins/response-ratelimiting/handler.lua @@ -6,6 +6,9 @@ local log = require "kong.plugins.response-ratelimiting.log" local header_filter = require "kong.plugins.response-ratelimiting.header_filter" +local kong = kong + + local ResponseRateLimitingHandler = BasePlugin:extend() @@ -22,20 +25,31 @@ end function ResponseRateLimitingHandler:header_filter(conf) ResponseRateLimitingHandler.super.header_filter(self) + + if kong.response.get_source() ~= "service" then + return + end + header_filter.execute(conf) end function ResponseRateLimitingHandler:log(conf) + ResponseRateLimitingHandler.super.log(self) + + if kong.response.get_source() ~= "service" then + return + end + local ctx = kong.ctx.plugin if not ctx.stop_log and ctx.usage then - ResponseRateLimitingHandler.super.log(self) log.execute(conf, ctx.identifier, ctx.current_timestamp, ctx.increments, ctx.usage) end end ResponseRateLimitingHandler.PRIORITY = 900 -ResponseRateLimitingHandler.VERSION = "0.1.0" +ResponseRateLimitingHandler.VERSION = "1.0.0" + return ResponseRateLimitingHandler