Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nginx/nginx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2009-02-24 10:29:55 +0300
committerIgor Sysoev <igor@sysoev.ru>2009-02-24 10:29:55 +0300
commit1966aedd6d4f7a61dd4b7b4ddbeadf56291b1621 (patch)
tree620573f5d732e45bd64cb5d6e7e9f75941be9fa3 /src
parent50273503aa9e449bf1905425936958a2825b0975 (diff)
axe r->port_text
Diffstat (limited to 'src')
-rw-r--r--src/http/ngx_http.c25
-rw-r--r--src/http/ngx_http_core_module.c2
-rw-r--r--src/http/ngx_http_core_module.h2
-rw-r--r--src/http/ngx_http_header_filter_module.c45
-rw-r--r--src/http/ngx_http_request.c2
-rw-r--r--src/http/ngx_http_request.h1
-rw-r--r--src/http/ngx_http_variables.c37
7 files changed, 57 insertions, 57 deletions
diff --git a/src/http/ngx_http.c b/src/http/ngx_http.c
index 080ef8e8e..c41f5bff0 100644
--- a/src/http/ngx_http.c
+++ b/src/http/ngx_http.c
@@ -1603,7 +1603,7 @@ ngx_http_cmp_dns_wildcards(const void *one, const void *two)
static ngx_int_t
ngx_http_init_listening(ngx_conf_t *cf, ngx_http_conf_port_t *port)
{
- ngx_uint_t i, a, last, bind_wildcard;
+ ngx_uint_t i, last, bind_wildcard;
ngx_listening_t *ls;
ngx_http_port_t *hport;
ngx_http_conf_addr_t *addr;
@@ -1626,16 +1626,16 @@ ngx_http_init_listening(ngx_conf_t *cf, ngx_http_conf_port_t *port)
bind_wildcard = 0;
}
- a = 0;
+ i = 0;
- while (a < last) {
+ while (i < last) {
- if (bind_wildcard && !addr[a].bind) {
- a++;
+ if (bind_wildcard && !addr[i].bind) {
+ i++;
continue;
}
- ls = ngx_http_add_listening(cf, &addr[a]);
+ ls = ngx_http_add_listening(cf, &addr[i]);
if (ls == NULL) {
return NGX_ERROR;
}
@@ -1647,21 +1647,12 @@ ngx_http_init_listening(ngx_conf_t *cf, ngx_http_conf_port_t *port)
ls->servers = hport;
- for (i = ls->addr_text.len - 1; i; i--) {
-
- if (ls->addr_text.data[i] == ':') {
- hport->port_text.len = ls->addr_text.len - i;
- hport->port_text.data = &ls->addr_text.data[i];
- break;
- }
- }
-
- if (a == last - 1) {
+ if (i == last - 1) {
hport->naddrs = last;
} else {
hport->naddrs = 1;
- a = 0;
+ i = 0;
}
switch (ls->sockaddr->sa_family) {
diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c
index 34dafaac6..3abd6d4fe 100644
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -2061,8 +2061,6 @@ ngx_http_subrequest(ngx_http_request_t *r,
c->data = sr;
}
- sr->port_text = r->port_text;
-
sr->variables = r->variables;
sr->log_handler = r->log_handler;
diff --git a/src/http/ngx_http_core_module.h b/src/http/ngx_http_core_module.h
index 018bd1bc9..3bf9e2270 100644
--- a/src/http/ngx_http_core_module.h
+++ b/src/http/ngx_http_core_module.h
@@ -200,8 +200,6 @@ typedef struct {
typedef struct {
- ngx_str_t port_text;
-
/* ngx_http_in_addr_t or ngx_http_in6_addr_t */
void *addrs;
ngx_uint_t naddrs;
diff --git a/src/http/ngx_http_header_filter_module.c b/src/http/ngx_http_header_filter_module.c
index f1a68617d..1874b5783 100644
--- a/src/http/ngx_http_header_filter_module.c
+++ b/src/http/ngx_http_header_filter_module.c
@@ -315,26 +315,22 @@ ngx_http_header_filter(ngx_http_request_t *r)
break;
}
-#if (NGX_HTTP_SSL)
- if (r->connection->ssl) {
- len += sizeof("Location: https://") - 1
- + host.len
- + r->headers_out.location->value.len + 2;
+ len += sizeof("Location: https://") - 1
+ + host.len
+ + r->headers_out.location->value.len + 2;
- if (clcf->port_in_redirect && port != 443) {
- len += r->port_text->len;
- }
+ if (clcf->port_in_redirect) {
- } else
+#if (NGX_HTTP_SSL)
+ if (r->connection->ssl)
+ port = (port == 443) ? 0 : port;
+ else
#endif
- {
- len += sizeof("Location: http://") - 1
- + host.len
- + r->headers_out.location->value.len + 2;
+ port = (port == 80) ? 0 : port;
+ }
- if (clcf->port_in_redirect && port != 80) {
- len += r->port_text->len;
- }
+ if (port) {
+ len += sizeof(":65535") - 1;
}
} else {
@@ -492,21 +488,8 @@ ngx_http_header_filter(ngx_http_request_t *r)
*b->last++ = ':'; *b->last++ = '/'; *b->last++ = '/';
b->last = ngx_copy(b->last, host.data, host.len);
- if (clcf->port_in_redirect) {
-#if (NGX_HTTP_SSL)
- if (r->connection->ssl) {
- if (port != 443) {
- b->last = ngx_copy(b->last, r->port_text->data,
- r->port_text->len);
- }
- } else
-#endif
- {
- if (port != 80) {
- b->last = ngx_copy(b->last, r->port_text->data,
- r->port_text->len);
- }
- }
+ if (port) {
+ b->last = ngx_sprintf(b->last, ":%ui", port);
}
b->last = ngx_copy(b->last, r->headers_out.location->value.data,
diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c
index bd1420043..d1dc290fc 100644
--- a/src/http/ngx_http_request.c
+++ b/src/http/ngx_http_request.c
@@ -300,8 +300,6 @@ ngx_http_init_request(ngx_event_t *rev)
port = c->listening->servers;
- r->port_text = &port->port_text;
-
r->connection = c;
if (port->naddrs > 1) {
diff --git a/src/http/ngx_http_request.h b/src/http/ngx_http_request.h
index ea3c6ab7c..d3ba95ee7 100644
--- a/src/http/ngx_http_request.h
+++ b/src/http/ngx_http_request.h
@@ -384,7 +384,6 @@ struct ngx_http_request_s {
ngx_http_post_subrequest_t *post_subrequest;
ngx_http_posted_request_t *posted_requests;
- ngx_str_t *port_text; /* ":80" */
ngx_http_virtual_names_t *virtual_names;
ngx_int_t phase_handler;
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;
}