在 openresty 的 access_by_lua_block 中使用 nginx 的 $http_upgrade

如何在 openresty 的 access_by_lua_block 中调用 NGINX 的 $http_upgrade 呢?

我想在这里使用它:

access_by_lua_block {
   ???
}
点赞
用户9783845
用户9783845

你可以使用 ngx.var.VARIABLE 或者 ngx.req.get_headers API 来获取任意请求头的值:

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

从文档中可以看出:

请注意,使用核心 $http_HEADER 变量的 ngx.var.HEADER API 调用可能更适合读取单个请求头。

2021-02-11 14:44:25