Skip to content

Commit d31a2e5

Browse files
committed
feat: add docstrings for embedded NGINX core/upstream vars to ngx.var.*
1 parent d02859d commit d31a2e5

File tree

1 file changed

+272
-5
lines changed

1 file changed

+272
-5
lines changed

meta/3rd/OpenResty/library/ngx.lua

Lines changed: 272 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1924,9 +1924,216 @@ function DICT:free_space() end
19241924
---
19251925
--- This API requires a relatively expensive metamethod call and it is recommended to avoid using it on hot code paths.
19261926
---
1927+
---@type table
1928+
ngx.var = {}
1929+
1930+
--- Embedded Variables
1931+
--- see https://nginx.org/en/docs/http/ngx_http_core_module.html#variables
1932+
1933+
--- client address in a binary form, value’s length is always 4 bytes for IPv4 addresses or 16 bytes for IPv6 addresses
1934+
---@type string
1935+
ngx.var.binary_remote_addr = nil
1936+
1937+
--- number of bytes sent to a client, not counting the response header; this variable is compatible with the “%B” parameter of the mod_log_config Apache module
1938+
---@type number
1939+
ngx.var.body_bytes_sent = nil
1940+
1941+
--- number of bytes sent to a client (1.3.8, 1.2.5)
1942+
---@type number
1943+
ngx.var.bytes_sent = nil
1944+
1945+
--- connection serial number (1.3.8, 1.2.5)
1946+
---@type string
1947+
ngx.var.connection = nil
1948+
1949+
--- current number of requests made through a connection (1.3.8, 1.2.5)
1950+
---@type string
1951+
ngx.var.connection_requests = nil
1952+
1953+
--- connection time in seconds with a milliseconds resolution (1.19.10)
1954+
---@type string
1955+
ngx.var.connection_time = nil
1956+
1957+
--- “Content-Length” request header field
1958+
---@type string
1959+
ngx.var.content_length = nil
1960+
1961+
--- “Content-Type” request header field
1962+
---@type string
1963+
ngx.var.content_type = nil
1964+
1965+
--- root or alias directive’s value for the current request
1966+
---@type string
1967+
ngx.var.document_root = nil
1968+
1969+
--- same as ngx.var.uri
1970+
---@type string
1971+
ngx.var.document_uri = nil
1972+
1973+
--- in this order of precedence: host name from the request line, or host name from the “Host” request header field, or the server name matching a request
1974+
---@type string
1975+
ngx.var.host = nil
1976+
1977+
--- host name
1978+
---@type string
1979+
ngx.var.hostname = nil
1980+
1981+
--- “on” if connection operates in SSL mode, or an empty string otherwise
1982+
---@type string '"on"'|'""'
1983+
ngx.var.https = nil
1984+
1985+
--- “?” if a request line has arguments, or an empty string otherwise
1986+
---@type string
1987+
ngx.var.is_args = nil
1988+
1989+
--- setting this variable enables response rate limiting; see limit_rate
1990+
---@type string
1991+
ngx.var.limit_rate = nil
1992+
1993+
--- current time in seconds with the milliseconds resolution (1.3.9, 1.2.6)
1994+
---@type string
1995+
ngx.var.msec = nil
1996+
1997+
--- nginx version
1998+
---@type string
1999+
ngx.var.nginx_version = nil
2000+
2001+
--- PID of the worker process
2002+
---@type string
2003+
ngx.var.pid = nil
2004+
2005+
--- “p” if request was pipelined, “.” otherwise (1.3.12, 1.2.7)
2006+
---@type string
2007+
ngx.var.pipe = nil
2008+
2009+
--- client address from the PROXY protocol header (1.5.12)
2010+
--- The PROXY protocol must be previously enabled by setting the proxy_protocol parameter in the listen directive.
2011+
---@type string
2012+
ngx.var.proxy_protocol_addr = nil
2013+
2014+
--- client port from the PROXY protocol header (1.11.0)
2015+
---
2016+
--- The PROXY protocol must be previously enabled by setting the proxy_protocol parameter in the listen directive.
2017+
---@type string
2018+
ngx.var.proxy_protocol_port = nil
2019+
2020+
--- server address from the PROXY protocol header (1.17.6)
2021+
---
2022+
--- The PROXY protocol must be previously enabled by setting the proxy_protocol parameter in the listen directive.
2023+
---@type string
2024+
ngx.var.proxy_protocol_server_addr = nil
2025+
2026+
--- server port from the PROXY protocol header (1.17.6)
2027+
---
2028+
--- The PROXY protocol must be previously enabled by setting the proxy_protocol parameter in the listen directive.
2029+
---@type string
2030+
ngx.var.proxy_protocol_server_port = nil
2031+
2032+
--- same as ngx.var.args
2033+
---@type string
2034+
ngx.var.query_string = nil
2035+
2036+
--- an absolute pathname corresponding to the root or alias directive’s value for the current request, with all symbolic links resolved to real paths
2037+
---@type string
2038+
ngx.var.realpath_root = nil
2039+
2040+
--- client address
2041+
---@type string
2042+
ngx.var.remote_addr = nil
2043+
2044+
--- client port
2045+
---@type string
2046+
ngx.var.remote_port = nil
2047+
2048+
--- user name supplied with the Basic authentication
2049+
---@type string
2050+
ngx.var.remote_user = nil
2051+
2052+
--- full original request line
2053+
---@type string
2054+
ngx.var.request = nil
2055+
2056+
--- request body
19272057
---
1928-
---@class ngx.var : table<string, any>
2058+
--- The variable’s value is made available in locations processed by the proxy_pass, fastcgi_pass, uwsgi_pass, and scgi_pass directives when the request body was read to a memory buffer.
2059+
---@type string
2060+
ngx.var.request_body = nil
2061+
2062+
--- name of a temporary file with the request body
19292063
---
2064+
--- At the end of processing, the file needs to be removed.
2065+
--- To always write the request body to a file, client_body_in_file_only needs to be enabled.
2066+
--- When the name of a temporary file is passed in a proxied request or in a request to a FastCGI/uwsgi/SCGI server, passing the request body should be disabled by the proxy_pass_request_body off, fastcgi_pass_request_body off, uwsgi_pass_request_body off, or scgi_pass_request_body off directives, respectively.
2067+
---@type string
2068+
ngx.var.request_body_file = nil
2069+
2070+
--- “OK” if a request has completed, or an empty string otherwise
2071+
---@type string
2072+
ngx.var.request_completion = nil
2073+
2074+
--- file path for the current request, based on the root or alias directives, and the request URI
2075+
---@type string
2076+
ngx.var.request_filename = nil
2077+
2078+
--- unique request identifier generated from 16 random bytes, in hexadecimal (1.11.0)
2079+
---@type string
2080+
ngx.var.request_id = nil
2081+
2082+
--- request length (including request line, header, and request body) (1.3.12, 1.2.7)
2083+
---@type string
2084+
ngx.var.request_length = nil
2085+
2086+
--- request method, usually “GET” or “POST”
2087+
---@type string
2088+
ngx.var.request_method = nil
2089+
2090+
--- request processing time in seconds with a milliseconds resolution (1.3.9, 1.2.6); time elapsed since the first bytes were read from the client
2091+
---@type string
2092+
ngx.var.request_time = nil
2093+
2094+
--- full original request URI (with arguments)
2095+
---@type string
2096+
ngx.var.request_uri = nil
2097+
2098+
--- request scheme, “http” or “https”
2099+
---@type string
2100+
ngx.var.scheme = nil
2101+
2102+
--- an address of the server which accepted a request
2103+
---
2104+
--- Computing a value of this variable usually requires one system call. To avoid a system call, the listen directives must specify addresses and use the bind parameter.
2105+
---@type string
2106+
ngx.var.server_addr = nil
2107+
2108+
--- name of the server which accepted a request
2109+
---@type string
2110+
ngx.var.server_name = nil
2111+
2112+
--- port of the server which accepted a request
2113+
---@type string
2114+
ngx.var.server_port = nil
2115+
2116+
--- request protocol, usually “HTTP/1.0”, “HTTP/1.1”, or “HTTP/2.0”
2117+
---@type string
2118+
ngx.var.server_protocol = nil
2119+
2120+
--- response status (1.3.2, 1.2.2)
2121+
---@type string
2122+
ngx.var.status = nil
2123+
2124+
--- local time in the ISO 8601 standard format (1.3.12, 1.2.7)
2125+
---@type string
2126+
ngx.var.time_iso8601 = nil
2127+
2128+
--- local time in the Common Log Format (1.3.12, 1.2.7)
2129+
---@type string
2130+
ngx.var.time_local = nil
2131+
2132+
--- current URI in request, normalized
2133+
--- The value of $uri may change during request processing, e.g. when doing internal redirects, or when using index files.
2134+
---@type string
2135+
ngx.var.uri = nil
2136+
19302137
--- Updating query arguments via the Nginx variable `$args` (or `ngx.var.args` in Lua) at runtime is also supported:
19312138
---
19322139
--- ```lua
@@ -1943,10 +2150,70 @@ function DICT:free_space() end
19432150
--- ```
19442151
---
19452152
--- regardless of the actual request query string.
1946-
---@field args string
1947-
---
1948-
---
1949-
ngx.var = {}
2153+
---@type string
2154+
ngx.var.args = nil
2155+
2156+
--- embedded upstream variables
2157+
--- https://nginx.org/en/docs/http/ngx_http_upstream_module.html#variables
2158+
2159+
--- IP address and port, or the path to the UNIX-domain socket of the upstream server.
2160+
--- If several servers were contacted during request processing, their addresses are separated by commas, e.g. “192.168.1.1:80, 192.168.1.2:80, unix:/tmp/sock”.
2161+
--- If an internal redirect from one server group to another happens, initiated by “X-Accel-Redirect” or error_page, then the server addresses from different groups are separated by colons, e.g. “192.168.1.1:80, 192.168.1.2:80, unix:/tmp/sock : 192.168.10.1:80, 192.168.10.2:80”.
2162+
--- If a server cannot be selected, the variable keeps the name of the server group.
2163+
---@type string
2164+
ngx.var.upstream_addr = nil
2165+
2166+
--- number of bytes received from an upstream server (1.11.4). Values from several connections are separated by commas and colons like addresses in the $upstream_addr variable.
2167+
---@type string
2168+
ngx.var.upstream_bytes_received = nil
2169+
2170+
--- number of bytes sent to an upstream server (1.15.8). Values from several connections are separated by commas and colons like addresses in the $upstream_addr variable.
2171+
---@type string
2172+
ngx.var.upstream_bytes_sent = nil
2173+
2174+
--- status of accessing a response cache (0.8.3). The status can be either “MISS”, “BYPASS”, “EXPIRED”, “STALE”, “UPDATING”, “REVALIDATED”, or “HIT”.
2175+
---@type string
2176+
ngx.var.upstream_cache_status = nil
2177+
2178+
--- time spent on establishing a connection with the upstream server (1.9.1)
2179+
--
2180+
--- the time is kept in seconds with millisecond resolution.
2181+
--- In case of SSL, includes time spent on handshake.
2182+
--- Times of several connections are separated by commas and colons like addresses in the $upstream_addr variable.
2183+
---@type string
2184+
ngx.var.upstream_connect_time = nil
2185+
2186+
--- time spent on receiving the response header from the upstream server (1.7.10)
2187+
--- the time is kept in seconds with millisecond resolution.
2188+
--- Times of several responses are separated by commas and colons like addresses in the $upstream_addr variable.
2189+
---@type string
2190+
ngx.var.upstream_header_time = nil
2191+
2192+
--- the time the request spent in the upstream queue (1.13.9).
2193+
--- the time is kept in seconds with millisecond resolution.
2194+
--- Times of several responses are separated by commas and colons like addresses in the $upstream_addr variable.
2195+
---@type string
2196+
ngx.var.upstream_queue_time = nil
2197+
2198+
--- the length of the response obtained from the upstream server (0.7.27).
2199+
--- the length is kept in bytes.
2200+
--- Lengths of several responses are separated by commas and colons like addresses in the $upstream_addr variable.
2201+
---@type string
2202+
ngx.var.upstream_response_length = nil
2203+
2204+
--- time spent on receiving the response from the upstream server
2205+
---
2206+
--- the time is kept in seconds with millisecond resolution.
2207+
--- Times of several responses are separated by commas and colons like addresses in the $upstream_addr variable.
2208+
---@type string
2209+
ngx.var.upstream_response_time = nil
2210+
2211+
--- status code of the response obtained from the upstream server.
2212+
--- Status codes of several responses are separated by commas and colons like addresses in the $upstream_addr variable.
2213+
--- If a server cannot be selected, the variable keeps the 502 (Bad Gateway) status code.
2214+
---@type string
2215+
ngx.var.upstream_status = nil
2216+
19502217

19512218
ngx.req = {}
19522219

0 commit comments

Comments
 (0)