mirror of
https://github.com/nginx/nginx.git
synced 2024-12-20 06:03:31 -06:00
nginx-0.0.1-2003-01-29-10:25:51 import
This commit is contained in:
parent
a19a85e600
commit
fe5cb6b9e9
@ -188,7 +188,7 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, char *dummy)
|
||||
|
||||
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 *cf, ngx_command_t *cmd, char *dummy)
|
||||
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 *cf, ngx_command_t *cmd, char *dummy)
|
||||
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 *cf, ngx_command_t *cmd, char *dummy)
|
||||
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 *cf, ngx_command_t *cmd, char *dummy)
|
||||
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;
|
||||
|
@ -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;
|
||||
|
@ -22,8 +22,6 @@ int ngx_http_proxy_handler(ngx_http_request_t *r);
|
||||
/**/
|
||||
|
||||
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, "servers: %0x" _ r->connection->servers);
|
||||
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_request_t *r, ngx_str_t uri)
|
||||
}
|
||||
|
||||
|
||||
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 *cf, ngx_command_t *cmd, char *conf)
|
||||
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;
|
||||
|
@ -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 {
|
||||
|
@ -397,14 +397,13 @@ static int ngx_http_process_request_headers(ngx_http_request_t *r)
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user