Only set cookies on paths that enable session affinity

This commit is contained in:
Zenara Daley 2018-11-19 11:42:12 -05:00
parent 82721e575d
commit 2b109b360b
4 changed files with 92 additions and 5 deletions

View file

@ -18,6 +18,7 @@ function _M.new(self, backend)
cookie_expires = backend["sessionAffinityConfig"]["cookieSessionAffinity"]["expires"],
cookie_max_age = backend["sessionAffinityConfig"]["cookieSessionAffinity"]["maxage"],
cookie_path = backend["sessionAffinityConfig"]["cookieSessionAffinity"]["path"],
cookie_locations = backend["sessionAffinityConfig"]["cookieSessionAffinity"]["locations"],
digest_func = digest_func,
traffic_shaping_policy = backend.trafficShapingPolicy,
alternative_backends = backend.alternativeBackends,
@ -81,7 +82,18 @@ function _M.balance(self)
if not key then
local random_str = string.format("%s.%s", ngx.now(), ngx.worker.pid())
key = encrypted_endpoint_string(self, random_str)
set_cookie(self, key)
if self.cookie_locations then
local locs = self.cookie_locations[ngx.var.host]
if locs ~= nil then
for _, path in pairs(locs) do
if ngx.var.location_path == path then
set_cookie(self, key)
break
end
end
end
end
end
return self.instance:find(key)