lua-nginx-module icon indicating copy to clipboard operation
lua-nginx-module copied to clipboard

Feature request: `ngx.req.get_header` to get a single header value

Open StarlightIbuki opened this issue 3 years ago • 3 comments

It would be useful if such an API is provided. Currently, people uses ngx.req.get_headers()[key] to get header value for key. This is of low efficiency. If we try to cache the result of get_headers(), we need to update the cache every time headers are changed(and it will be impractical if other modules may change headers). Even the most trivial implementation(brute force search) could have a better performance than the ngx.req.get_headers()[key] solution. And for most cases, the header should be pre-hashed. Is there any reason we do not add the API? Thank you.

StarlightIbuki avatar Apr 21 '22 05:04 StarlightIbuki

https://www.nginx.com/resources/wiki/start/topics/examples/headers_management/

StarlightIbuki avatar Apr 21 '22 06:04 StarlightIbuki

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

zhuizhuhaomeng avatar Apr 21 '22 15:04 zhuizhuhaomeng

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

Yes, it solves some of the problems. But $http_HEADER does not have a limitation on headers to search, which behaves differently from ngx.req.get_headers. That may be important in some cases.

StarlightIbuki avatar Apr 22 '22 08:04 StarlightIbuki