Merge pull request #110 from hnakamur/update_for_nginx_1_23_0

Update xfwd type changed in nginx 1.23.0 (Fixes #109)
This commit is contained in:
Lee 2022-06-21 23:30:42 -05:00 committed by GitHub
commit cbaa35461c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -146,7 +146,11 @@ ngx_http_geoip2_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v,
MMDB_entry_data_s entry_data; MMDB_entry_data_s entry_data;
ngx_http_geoip2_conf_t *gcf; ngx_http_geoip2_conf_t *gcf;
ngx_addr_t addr; ngx_addr_t addr;
#if defined(nginx_version) && nginx_version >= 1023000
ngx_table_elt_t *xfwd;
#else
ngx_array_t *xfwd; ngx_array_t *xfwd;
#endif
u_char *p; u_char *p;
ngx_str_t val; ngx_str_t val;
@ -169,9 +173,15 @@ ngx_http_geoip2_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v,
addr.sockaddr = r->connection->sockaddr; addr.sockaddr = r->connection->sockaddr;
addr.socklen = r->connection->socklen; addr.socklen = r->connection->socklen;
#if defined(nginx_version) && nginx_version >= 1023000
xfwd = r->headers_in.x_forwarded_for;
if (xfwd != NULL && gcf->proxies != NULL) {
#else
xfwd = &r->headers_in.x_forwarded_for; xfwd = &r->headers_in.x_forwarded_for;
if (xfwd->nelts > 0 && gcf->proxies != NULL) { if (xfwd->nelts > 0 && gcf->proxies != NULL) {
#endif
(void) ngx_http_get_forwarded_addr(r, &addr, xfwd, NULL, (void) ngx_http_get_forwarded_addr(r, &addr, xfwd, NULL,
gcf->proxies, gcf->proxy_recursive); gcf->proxies, gcf->proxy_recursive);
} }