Created
September 8, 2014 15:29
-
-
Save vdel26/56100bb4ae8c527f541e to your computer and use it in GitHub Desktop.
detect 409 from 3scale
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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