aboutsummaryrefslogtreecommitdiff
path: root/src/http/modules/ngx_http_geoip_module.c
diff options
context:
space:
mode:
authorRuslan Ermilov <ru@nginx.com>2013-02-27 13:29:50 +0000
committerRuslan Ermilov <ru@nginx.com>2013-02-27 13:29:50 +0000
commit67a68720b7f08542c891d7b9ef08f07e3543b0e4 (patch)
treeb61423ee7b49a7280f87d66606c96785681d71ad /src/http/modules/ngx_http_geoip_module.c
parent40ea120b34342a3aa80f27378c7f05360b2da7a0 (diff)
downloadnginx-67a68720b7f08542c891d7b9ef08f07e3543b0e4.tar.gz
nginx-67a68720b7f08542c891d7b9ef08f07e3543b0e4.zip
Correctly handle multiple X-Forwarded-For headers (ticket #106).
Diffstat (limited to 'src/http/modules/ngx_http_geoip_module.c')
-rw-r--r--src/http/modules/ngx_http_geoip_module.c22
1 files changed, 10 insertions, 12 deletions
diff --git a/src/http/modules/ngx_http_geoip_module.c b/src/http/modules/ngx_http_geoip_module.c
index 364106519..576fc5f3c 100644
--- a/src/http/modules/ngx_http_geoip_module.c
+++ b/src/http/modules/ngx_http_geoip_module.c
@@ -240,19 +240,18 @@ static u_long
ngx_http_geoip_addr(ngx_http_request_t *r, ngx_http_geoip_conf_t *gcf)
{
ngx_addr_t addr;
- ngx_table_elt_t *xfwd;
+ ngx_array_t *xfwd;
struct sockaddr_in *sin;
addr.sockaddr = r->connection->sockaddr;
addr.socklen = r->connection->socklen;
/* addr.name = r->connection->addr_text; */
- xfwd = r->headers_in.x_forwarded_for;
+ xfwd = &r->headers_in.x_forwarded_for;
- if (xfwd != NULL && gcf->proxies != NULL) {
- (void) ngx_http_get_forwarded_addr(r, &addr, xfwd->value.data,
- xfwd->value.len, gcf->proxies,
- gcf->proxy_recursive);
+ if (xfwd->nelts > 0 && gcf->proxies != NULL) {
+ (void) ngx_http_get_forwarded_addr(r, &addr, xfwd, NULL,
+ gcf->proxies, gcf->proxy_recursive);
}
#if (NGX_HAVE_INET6)
@@ -293,7 +292,7 @@ static geoipv6_t
ngx_http_geoip_addr_v6(ngx_http_request_t *r, ngx_http_geoip_conf_t *gcf)
{
ngx_addr_t addr;
- ngx_table_elt_t *xfwd;
+ ngx_array_t *xfwd;
in_addr_t addr4;
struct in6_addr addr6;
struct sockaddr_in *sin;
@@ -303,12 +302,11 @@ ngx_http_geoip_addr_v6(ngx_http_request_t *r, ngx_http_geoip_conf_t *gcf)
addr.socklen = r->connection->socklen;
/* addr.name = r->connection->addr_text; */
- xfwd = r->headers_in.x_forwarded_for;
+ xfwd = &r->headers_in.x_forwarded_for;
- if (xfwd != NULL && gcf->proxies != NULL) {
- (void) ngx_http_get_forwarded_addr(r, &addr, xfwd->value.data,
- xfwd->value.len, gcf->proxies,
- gcf->proxy_recursive);
+ if (xfwd->nelts > 0 && gcf->proxies != NULL) {
+ (void) ngx_http_get_forwarded_addr(r, &addr, xfwd, NULL,
+ gcf->proxies, gcf->proxy_recursive);
}
switch (addr.sockaddr->sa_family) {