# HG changeset patch # User Igor Sysoev # Date 1043859768 0 # Node ID 058f01f78761c4677797bf796617face7915eba2 # Parent cad6c2f43283beeb06a48b4668d1bb3f7f8dac87 nginx-0.0.1-2003-01-29-20:02:48 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 @@ -348,6 +348,7 @@ static char *ngx_http_block(ngx_conf_t * ls->ctx = ctx; ls->servers = &in_port[p]; +#if 0 if (in_port[p].addr.nelts == 1) { in_addr = (ngx_http_in_addr_t *) in_port[p].addr.elts; @@ -359,10 +360,24 @@ static char *ngx_http_block(ngx_conf_t * ls->servers = NULL; } } +#endif ngx_log_debug(cf->log, "ls ctx: %d:%08x" _ in_port[p].port _ ls->ctx); } } + /* DEBUG STUFF */ + in_port = (ngx_http_in_port_t *) in_ports.elts; + for (p = 0; p < in_ports.nelts; p++) { +ngx_log_debug(cf->log, "port: %d" _ in_port[p].port); + in_addr = (ngx_http_in_addr_t *) in_port[p].addr.elts; + for (a = 0; a < in_port[p].addr.nelts; a++) { + char ip[20]; + ngx_inet_ntop(AF_INET, &in_addr[a].addr, ip, 20); +ngx_log_debug(cf->log, "%s %08x" _ ip _ in_addr[a].core_srv_conf); + } + } + /**/ + return NGX_CONF_OK; } 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 @@ -138,12 +138,15 @@ struct ngx_http_request_s { ngx_connection_t *connection; - u_int in_addr; + u_int in_addr; + + int port; + ngx_str_t port_name; - int filter; + int filter; - ssize_t client_content_length; - char *discarded_buffer; + ssize_t client_content_length; + char *discarded_buffer; ngx_str_t path; int path_err; 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 @@ -117,13 +117,13 @@ ngx_log_debug(r->connection->log, "serve /* AF_INET only */ in_port = (ngx_http_in_port_t *) r->connection->servers; + in_addr = (ngx_http_in_addr_t *) in_port->addr.elts; 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) { @@ -203,7 +203,7 @@ ngx_log_debug(r->connection->log, "loc_c int ngx_http_core_translate_handler(ngx_http_request_t *r) { - int i, rc, len, f_offset, l_offset; + int i, rc, len, port_len, f_offset, l_offset; char *buf, *location, *last; ngx_err_t err; ngx_table_elt_t *h; @@ -245,14 +245,34 @@ ngx_log_debug(r->connection->log, "doc_r s_name = (ngx_http_server_name_t *) scf->server_names.elts; + if (r->port == 0) { +#if 0 + struct sockaddr_in *addr_in; + addr_in = (struct sockaddr_in *) r->connection->sockaddr; + r->port = ntohs(addr_in->sin_port); +#else + ngx_http_in_port_t *in_port; + in_port = (ngx_http_in_port_t *) r->connection->servers; + r->port = in_port->port; +#endif + if (r->port != 80) { + ngx_test_null(r->port_name.data, ngx_palloc(r->pool, 7), + NGX_HTTP_INTERNAL_SERVER_ERROR); + r->port_name.len = ngx_snprintf(r->port_name.data, 7, ":%d", + r->port); + } + } + + port_len = (r->port != 80) ? r->port_name.len : 0; + /* "+ 7" is "http://" */ - if (loc_conf->doc_root.len > s_name[0].name.len + 7) { + if (loc_conf->doc_root.len > 7 + s_name[0].name.len + port_len) { len = loc_conf->doc_root.len; f_offset = 0; - l_offset = len - (s_name[0].name.len + 7); + l_offset = len - (7 + s_name[0].name.len + port_len); } else { - len = s_name[0].name.len + 7; + len = 7 + s_name[0].name.len + port_len; f_offset = len - loc_conf->doc_root.len; l_offset = 0; } @@ -367,6 +387,10 @@ ngx_log_debug(r->connection->log, "HTTP ngx_memcpy(location, "http://", 7); ngx_memcpy(location + 7, s_name[0].name.data, s_name[0].name.len); + if (port_len) { + ngx_memcpy(location + 7 + s_name[0].name.len, r->port_name.data, + port_len); + } *last++ = '/'; *last = '\0';