summaryrefslogtreecommitdiffhomepage
path: root/src/http/ngx_http_request.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/http/ngx_http_request.c')
-rw-r--r--src/http/ngx_http_request.c33
1 files changed, 15 insertions, 18 deletions
diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c
index 557de6696..41c1cda04 100644
--- a/src/http/ngx_http_request.c
+++ b/src/http/ngx_http_request.c
@@ -931,7 +931,7 @@ ngx_http_ssl_servername(ngx_ssl_conn_t *ssl_conn, int *ad, void *arg)
goto done;
}
- rc = ngx_http_validate_host(&host, c->pool, 1);
+ rc = ngx_http_validate_host(&host, NULL, c->pool, 1);
if (rc == NGX_ERROR) {
goto error;
@@ -1107,6 +1107,7 @@ ngx_http_process_request_line(ngx_event_t *rev)
ssize_t n;
ngx_int_t rc, rv;
ngx_str_t host;
+ in_port_t port;
ngx_connection_t *c;
ngx_http_request_t *r;
@@ -1169,7 +1170,7 @@ ngx_http_process_request_line(ngx_event_t *rev)
host.len = r->host_end - r->host_start;
host.data = r->host_start;
- rc = ngx_http_validate_host(&host, r->pool, 0);
+ rc = ngx_http_validate_host(&host, &port, r->pool, 0);
if (rc == NGX_DECLINED) {
ngx_log_error(NGX_LOG_INFO, c->log, 0,
@@ -1188,6 +1189,7 @@ ngx_http_process_request_line(ngx_event_t *rev)
}
r->headers_in.server = host;
+ r->port = port;
}
if (r->http_version < NGX_HTTP_VERSION_10) {
@@ -1846,9 +1848,9 @@ static ngx_int_t
ngx_http_process_host(ngx_http_request_t *r, ngx_table_elt_t *h,
ngx_uint_t offset)
{
- u_char *p;
- ngx_int_t rc;
- ngx_str_t host;
+ ngx_int_t rc;
+ ngx_str_t host;
+ in_port_t port;
if (r->headers_in.host) {
ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
@@ -1865,7 +1867,7 @@ ngx_http_process_host(ngx_http_request_t *r, ngx_table_elt_t *h,
host = h->value;
- rc = ngx_http_validate_host(&host, r->pool, 0);
+ rc = ngx_http_validate_host(&host, &port, r->pool, 0);
if (rc == NGX_DECLINED) {
ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
@@ -1888,17 +1890,7 @@ ngx_http_process_host(ngx_http_request_t *r, ngx_table_elt_t *h,
}
r->headers_in.server = host;
-
- p = ngx_strlchr(h->value.data + host.len,
- h->value.data + h->value.len, ':');
-
- if (p) {
- rc = ngx_atoi(p + 1, h->value.data + h->value.len - p - 1);
-
- if (rc > 0 && rc < 65536) {
- r->port = rc;
- }
- }
+ r->port = port;
return NGX_OK;
}
@@ -2182,7 +2174,8 @@ ngx_http_process_request(ngx_http_request_t *r)
ngx_int_t
-ngx_http_validate_host(ngx_str_t *host, ngx_pool_t *pool, ngx_uint_t alloc)
+ngx_http_validate_host(ngx_str_t *host, in_port_t *portp, ngx_pool_t *pool,
+ ngx_uint_t alloc)
{
u_char *h, ch;
size_t i, dot_pos, host_len;
@@ -2370,6 +2363,10 @@ ngx_http_validate_host(ngx_str_t *host, ngx_pool_t *pool, ngx_uint_t alloc)
host->len = host_len;
+ if (portp) {
+ *portp = port;
+ }
+
return NGX_OK;
}