ngx_http_posted_request_t *pr);
ngx_int_t ngx_http_set_virtual_server(ngx_http_request_t *r,
ngx_str_t *host);
-ngx_int_t ngx_http_validate_host(ngx_str_t *host, ngx_pool_t *pool,
- ngx_uint_t alloc);
+ngx_int_t ngx_http_validate_host(ngx_str_t *host, in_port_t *port,
+ ngx_pool_t *pool, ngx_uint_t alloc);
void ngx_http_close_request(ngx_http_request_t *r, ngx_int_t rc);
void ngx_http_finalize_request(ngx_http_request_t *r, ngx_int_t rc);
void ngx_http_free_request(ngx_http_request_t *r, ngx_int_t rc);
case sw_host_end:
+ if (ch == ':') {
+ state = sw_port;
+ break;
+ }
+
r->host_end = p;
if (r->method == NGX_HTTP_CONNECT) {
- if (ch == ':') {
- state = sw_port;
- break;
- }
-
return NGX_HTTP_PARSE_INVALID_REQUEST;
}
switch (ch) {
- case ':':
- state = sw_port;
- break;
case '/':
r->uri_start = p;
state = sw_after_slash_in_uri;
case sw_port:
if (ch >= '0' && ch <= '9') {
- if (r->port >= 6553 && (r->port > 6553 || (ch - '0') > 5)) {
- return NGX_HTTP_PARSE_INVALID_REQUEST;
- }
-
- r->port = r->port * 10 + (ch - '0');
break;
}
+ r->host_end = p;
+
if (r->method == NGX_HTTP_CONNECT) {
if (ch == ' ') {
state = sw_http_09;
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;
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;
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,
}
r->headers_in.server = host;
+ r->port = port;
}
if (r->http_version < NGX_HTTP_VERSION_10) {
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,
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,
}
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;
}
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;
host->len = host_len;
+ if (portp) {
+ *portp = port;
+ }
+
return NGX_OK;
}
static ngx_int_t
ngx_http_v2_parse_authority(ngx_http_request_t *r, ngx_str_t *value)
{
- u_char *p;
- ngx_int_t rc;
+ ngx_int_t rc;
+ in_port_t port;
if (r->host_start) {
ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
r->host_start = value->data;
r->host_end = value->data + value->len;
- rc = ngx_http_validate_host(value, r->pool, 0);
+ rc = ngx_http_validate_host(value, &port, r->pool, 0);
if (rc == NGX_DECLINED) {
ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
}
r->headers_in.server = *value;
-
- p = ngx_strlchr(r->host_start + value->len, r->host_end, ':');
-
- if (p) {
- rc = ngx_atoi(p + 1, r->host_end - p - 1);
-
- if (rc > 0 && rc < 65536) {
- r->port = rc;
- }
- }
+ r->port = port;
return NGX_OK;
}
u_char *p;
ngx_int_t rc;
ngx_str_t host;
+ in_port_t port;
if (r->request_line.len) {
return NGX_OK;
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, r->connection->log, 0,
}
r->headers_in.server = host;
-
- p = ngx_strlchr(r->host_start + host.len, r->host_end, ':');
-
- if (p) {
- rc = ngx_atoi(p + 1, r->host_end - p - 1);
-
- if (rc > 0 && rc < 65536) {
- r->port = rc;
- }
- }
+ r->port = port;
}
if (ngx_list_init(&r->headers_in.headers, r->pool, 20,