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
index 4e7f8ca..ec10141 100644
--- a/src/http/ngx_http.c
+++ b/src/http/ngx_http.c
@@ -188,7 +188,7 @@
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 @@
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 @@
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 @@
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 @@
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
index 810fda2..1490c98 100644
--- a/src/http/ngx_http.h
+++ b/src/http/ngx_http.h
@@ -74,7 +74,7 @@
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 @@
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
index b667e3c..35a3b75 100644
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -22,8 +22,6 @@
/**/
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 @@
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 @@
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 @@
}
-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 @@
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
index 37fe17e..522cb25 100644
--- 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 @@
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
index 82f0d2d..26e67f8 100644
--- a/src/http/ngx_http_event.c
+++ b/src/http/ngx_http_event.c
@@ -397,14 +397,13 @@
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;