Search code examples
nginxluaopenresty

nginx $http_upgrade in openresty access_by_lua_block


what is the name or how ca I call $http_upgrade of NGINX in OPENRESTY access_by_lua_block

so I can use it here

access_by_lua_block {
   ???
}

Solution

  • You can use either ngx.var.VARIABLE or ngx.req.get_headers API to get a value of any request header:

    access_by_lua_block {
        ngx.log(ngx.INFO, ngx.var.http_upgrade)
        ngx.log(ngx.INFO, ngx.req.get_headers()['upgrade'])
    }
    

    From the documentation:

    Note that the ngx.var.HEADER API call, which uses core $http_HEADER variables, may be more preferable for reading individual request headers.