Skip to content

Instantly share code, notes, and snippets.

@vdel26
Created September 8, 2014 15:29
Show Gist options
  • Select an option

  • Save vdel26/56100bb4ae8c527f541e to your computer and use it in GitHub Desktop.

Select an option

Save vdel26/56100bb4ae8c527f541e to your computer and use it in GitHub Desktop.
detect 409 from 3scale
function error_authorization_failed(service)
ngx.status = 409
ngx.header.content_type = service.auth_failed_headers
ngx.print("Limit exceeded")
ngx.exit(ngx.HTTP_OK)
end
function authrep(params, service)
ngx.var.cached_key = ngx.var.cached_key .. ":" .. ngx.var.usage
local api_keys = ngx.shared.api_keys
local is_known = api_keys:get(ngx.var.cached_key)
if is_known ~= 200 then
local res = ngx.location.capture("/threescale_authrep", { share_all_vars = true })
if res.status ~= 200 then
api_keys:delete(ngx.var.cached_key)
ngx.status = res.status
ngx.header.content_type = "application/json"
-- return different response for 409 and 403
if res.status == 409 then
error_over_limit(service)
else
error_authorization_failed(service)
end
--
else
api_keys:set(ngx.var.cached_key,200)
end
ngx.var.cached_key = nil
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment