diff options
author | Igor Sysoev <igor@sysoev.ru> | 2009-02-24 07:29:55 +0000 |
---|---|---|
committer | Igor Sysoev <igor@sysoev.ru> | 2009-02-24 07:29:55 +0000 |
commit | 1966aedd6d4f7a61dd4b7b4ddbeadf56291b1621 (patch) | |
tree | 620573f5d732e45bd64cb5d6e7e9f75941be9fa3 /src/http/ngx_http_variables.c | |
parent | 50273503aa9e449bf1905425936958a2825b0975 (diff) | |
download | nginx-1966aedd6d4f7a61dd4b7b4ddbeadf56291b1621.tar.gz nginx-1966aedd6d4f7a61dd4b7b4ddbeadf56291b1621.zip |
axe r->port_text
Diffstat (limited to 'src/http/ngx_http_variables.c')
-rw-r--r-- | src/http/ngx_http_variables.c | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/src/http/ngx_http_variables.c b/src/http/ngx_http_variables.c index 81c8528fe..75ec740ca 100644 --- a/src/http/ngx_http_variables.c +++ b/src/http/ngx_http_variables.c @@ -956,11 +956,44 @@ static ngx_int_t ngx_http_variable_server_port(ngx_http_request_t *r, ngx_http_variable_value_t *v, uintptr_t data) { - v->len = r->port_text->len - 1; + ngx_uint_t port; + struct sockaddr_in *sin; +#if (NGX_HAVE_INET6) + struct sockaddr_in6 *sin6; +#endif + + v->len = 0; v->valid = 1; v->no_cacheable = 0; v->not_found = 0; - v->data = r->port_text->data + 1; + + if (ngx_http_server_addr(r, NULL) != NGX_OK) { + return NGX_ERROR; + } + + v->data = ngx_pnalloc(r->pool, sizeof("65535") - 1); + if (v->data == NULL) { + return NGX_ERROR; + } + + switch (r->connection->local_sockaddr->sa_family) { + +#if (NGX_HAVE_INET6) + case AF_INET6: + sin6 = (struct sockaddr_in6 *) r->connection->local_sockaddr; + port = ntohs(sin6->sin6_port); + break; +#endif + + default: /* AF_INET */ + sin = (struct sockaddr_in *) r->connection->local_sockaddr; + port = ntohs(sin->sin_port); + break; + } + + if (port > 0 && port < 65536) { + v->len = ngx_sprintf(v->data, "%ui", port) - v->data; + } return NGX_OK; } |