# HG changeset patch # User Igor Sysoev # Date 1043825151 0 # Node ID cad6c2f43283beeb06a48b4668d1bb3f7f8dac87 # Parent 27b628ef907ea61c82f75f9a5f56c0a0e10f93ac nginx-0.0.1-2003-01-29-10:25:51 import diff --git a/src/http/ngx_http.c b/src/http/ngx_http.c --- a/src/http/ngx_http.c +++ b/src/http/ngx_http.c @@ -188,7 +188,7 @@ static char *ngx_http_block(ngx_conf_t * ngx_log_error(NGX_LOG_ERR, cf->log, 0, "duplicate default server in %s:%d", - lscf[l].conf_file->file.name.data, + lscf[l].file_name.data, lscf[l].line); return NGX_CONF_ERROR; @@ -212,7 +212,7 @@ static char *ngx_http_block(ngx_conf_t * sizeof(ngx_http_in_addr_t)); inaddr->addr = lscf[l].addr; - inaddr->flags = lscf[l].flags; + inaddr->flags = lscf[l].flags; inaddr->core_srv_conf = cscf[s]; ngx_init_array(inaddr->names, cf->pool, 10, @@ -231,7 +231,7 @@ static char *ngx_http_block(ngx_conf_t * NGX_CONF_ERROR); inaddr->addr = lscf[l].addr; - inaddr->flags = lscf[l].flags; + inaddr->flags = lscf[l].flags; inaddr->core_srv_conf = cscf[s]; ngx_init_array(inaddr->names, cf->pool, 10, @@ -256,7 +256,7 @@ static char *ngx_http_block(ngx_conf_t * NGX_CONF_ERROR); inaddr->addr = lscf[l].addr; - inaddr->flags = lscf[l].flags; + inaddr->flags = lscf[l].flags; inaddr->core_srv_conf = cscf[s]; ngx_init_array(inaddr->names, cf->pool, 10, @@ -346,7 +346,7 @@ static char *ngx_http_block(ngx_conf_t * ls->handler = ngx_http_init_connection; ls->log = cf->log; ls->ctx = ctx; - ls->servers = &in_port[p].addr; + ls->servers = &in_port[p]; if (in_port[p].addr.nelts == 1) { in_addr = (ngx_http_in_addr_t *) in_port[p].addr.elts; diff --git a/src/http/ngx_http.h b/src/http/ngx_http.h --- a/src/http/ngx_http.h +++ b/src/http/ngx_http.h @@ -74,7 +74,7 @@ typedef struct { typedef struct { - ngx_str_t host_name; + int host_name_len; ngx_table_elt_t *host; ngx_table_elt_t *connection; @@ -138,6 +138,8 @@ struct ngx_http_request_s { ngx_connection_t *connection; + u_int in_addr; + int filter; ssize_t client_content_length; diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c --- a/src/http/ngx_http_core_module.c +++ b/src/http/ngx_http_core_module.c @@ -22,8 +22,6 @@ int ngx_http_proxy_handler(ngx_http_requ /**/ static int ngx_http_core_index_handler(ngx_http_request_t *r); -static ngx_http_conf_ctx_t *ngx_http_find_server_conf(ngx_http_request_t *r, - void *addr); static char *ngx_server_block(ngx_conf_t *cf, ngx_command_t *cmd, char *dummy); static char *ngx_location_block(ngx_conf_t *cf, ngx_command_t *cmd, @@ -98,9 +96,12 @@ ngx_module_t ngx_http_core_module = { int ngx_http_handler(ngx_http_request_t *r) { - int rc, i; - ngx_http_module_t *module; - ngx_http_conf_ctx_t *ctx; + int rc, a, n, i; + ngx_http_module_t *module; + ngx_http_conf_ctx_t *ctx; + ngx_http_in_port_t *in_port; + ngx_http_in_addr_t *in_addr; + ngx_http_server_name_t *name; r->connection->unexpected_eof = 0; r->lingering_close = 1; @@ -112,7 +113,47 @@ ngx_log_debug(r->connection->log, "serve ctx = (ngx_http_conf_ctx_t *) r->connection->ctx; } else { - ctx = ngx_http_find_server_conf(r, r->connection->servers); + + /* AF_INET only */ + + in_port = (ngx_http_in_port_t *) r->connection->servers; + + a = 0; + + if (in_port->addr.nelts > 1) { + /* find r->in_addr, getsockname() */ + + in_addr = (ngx_http_in_addr_t *) in_port->addr.elts; + for ( /* void */ ; a < in_port->addr.nelts; a++) { + + if (in_addr[a].addr == INADDR_ANY) { + break; + } + + if (in_addr[a].addr == r->in_addr) { + break; + } + } + } + + ctx = in_addr[a].core_srv_conf->ctx; + + if (r->headers_in.host_name_len > 0) { + + name = (ngx_http_server_name_t *) in_addr[a].names.elts; + for (n = 0; n < in_addr[a].names.nelts; n++) { + if (r->headers_in.host_name_len != name[n].name.len) { + continue; + } + + if (ngx_strncasecmp(r->headers_in.host->value.data, + name[n].name.data, + r->headers_in.host_name_len) == 0) { + ctx = name->core_srv_conf->ctx; + break; + } + } + } } r->srv_conf = ctx->srv_conf; @@ -454,40 +495,6 @@ int ngx_http_internal_redirect(ngx_http_ } -static ngx_http_conf_ctx_t *ngx_http_find_server_conf(ngx_http_request_t *r, - void *addr) -{ - int i, len; - ngx_http_in_addr_t *in_addr; - ngx_http_server_name_t *name; - - /* AF_INET only */ - - /* BUG: need cycle thru addr[]->elts */ - - in_addr = (ngx_http_in_addr_t *) addr; - - if (r->headers_in.host == NULL) { - return in_addr->core_srv_conf->ctx; - } - - len = r->headers_in.host_name.len; - name = (ngx_http_server_name_t *) in_addr->names.elts; - for (i = 0; i < in_addr->names.nelts; i++) { - if (len != name->name.len) { - continue; - } - - if (ngx_strncasecmp(r->headers_in.host_name.data, - name->name.data, len) == 0) { - return name->core_srv_conf->ctx; - } - } - - return in_addr->core_srv_conf->ctx; -} - - static char *ngx_server_block(ngx_conf_t *cf, ngx_command_t *cmd, char *dummy) { int i, j; @@ -796,7 +803,7 @@ static char *ngx_set_listen(ngx_conf_t * ls->family = AF_INET; ls->addr = INADDR_ANY; ls->flags = 0; - ls->conf_file = cf->conf_file; + ls->file_name = cf->conf_file->file.name; ls->line = cf->conf_file->line; args = (ngx_str_t *) cf->args->elts; diff --git a/src/http/ngx_http_core_module.h b/src/http/ngx_http_core_module.h --- a/src/http/ngx_http_core_module.h +++ b/src/http/ngx_http_core_module.h @@ -8,12 +8,12 @@ typedef struct { - int addr; - int port; - int family; - int flags; /* 'default' */ - ngx_conf_file_t *conf_file; - int line; + int addr; + int port; + int family; + int flags; /* 'default' */ + ngx_str_t file_name; + int line; } ngx_http_listen_t; @@ -23,30 +23,33 @@ typedef struct { ngx_array_t listen; /* 'listen', array of ngx_http_listen_t */ ngx_array_t server_names; /* 'server_name', array of ngx_http_server_name_t */ - ngx_http_conf_ctx_t *ctx; + ngx_http_conf_ctx_t *ctx; /* server ctx */ } ngx_http_core_srv_conf_t; -typedef struct { - ngx_str_t name; - ngx_http_core_srv_conf_t *core_srv_conf; -} ngx_http_server_name_t; - +/* list of structures to find core_srv_conf quickly at run time */ typedef struct { int port; - ngx_array_t addr; + ngx_array_t addr; /* array of ngx_http_in_addr_t */ } ngx_http_in_port_t; typedef struct { u_int32_t addr; - ngx_array_t names; - int flags; - ngx_http_core_srv_conf_t *core_srv_conf; + ngx_array_t names; /* array of ngx_http_server_name_t */ + ngx_http_core_srv_conf_t *core_srv_conf; /* default server conf + for this address:port */ + int flags; } ngx_http_in_addr_t; #define NGX_HTTP_DEFAULT_SERVER 1 +typedef struct { + ngx_str_t name; + ngx_http_core_srv_conf_t *core_srv_conf; /* virtual name server conf */ +} ngx_http_server_name_t; + + typedef struct { diff --git a/src/http/ngx_http_event.c b/src/http/ngx_http_event.c --- a/src/http/ngx_http_event.c +++ b/src/http/ngx_http_event.c @@ -397,14 +397,13 @@ static int ngx_http_process_request_head break; } } - r->headers_in.host_name.len = len; - r->headers_in.host_name.data = r->headers_in.host->value.data; + r->headers_in.host_name_len = len; } else { if (r->http_version > NGX_HTTP_VERSION_10) { return ngx_http_error(r, NGX_HTTP_BAD_REQUEST); } - r->headers_in.host_name.len = 0; + r->headers_in.host_name_len = 0; } return NGX_OK;