Quantcast
Channel: Nginx Forum - How to...
Viewing all articles
Browse latest Browse all 4759

Re: How to set response from rewrite_by_lua_file directive

$
0
0
Downloading seems to take forever. The contents of my key_lookup.lua is below:

local cjson = require("cjson")

local headers = ngx.req.get_headers()
local key = headers["X-KEY-HEADER"]

if key then
local value = ngx.shared.lookuptable[key]
if value then
ngx.req.set_header("X-VALUE-HEADER", tostring(value))
else
ngx.log(ngx.ERR, "Unable to find value for key " .. tostring(key))
ngx.status = ngx.HTTP_UNAUTHORIZED
ngx.say(cjson.encode({error = {code = "401 Unauthorized", cause = "10000"}}))
ngx.exit(ngx.HTTP_UNAUTHORIZED)
end
else
ngx.log(ngx.ERR, "X-KEY-HEADER not specified")
ngx.exit(ngx.HTTP_UNAUTHORIZED)
end

Viewing all articles
Browse latest Browse all 4759

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>