diff options
author | Igor Sysoev <igor@sysoev.ru> | 2006-05-11 14:43:47 +0000 |
---|---|---|
committer | Igor Sysoev <igor@sysoev.ru> | 2006-05-11 14:43:47 +0000 |
commit | 3338cfdfbc5522ca96319ece6d21ddc4d1dce45d (patch) | |
tree | 1e668fefd76a974c8ffdb0db6813022a6eb64e76 /src/http/ngx_http_request.c | |
parent | 418843dc7f2ff90ae371f41e5fea810e10e59317 (diff) | |
download | nginx-3338cfdfbc5522ca96319ece6d21ddc4d1dce45d.tar.gz nginx-3338cfdfbc5522ca96319ece6d21ddc4d1dce45d.zip |
nginx-0.3.46-RELEASE importrelease-0.3.46
*) Feature: the "proxy_hide_header", "proxy_pass_header",
"fastcgi_hide_header", and "fastcgi_pass_header" directives.
*) Change: the "proxy_pass_x_powered_by", "fastcgi_x_powered_by", and
"proxy_pass_server" directives were canceled.
*) Feature: the "X-Accel-Buffering" response header line is supported
in proxy mode.
*) Bugfix: the reconfiguration bug and memory leaks in the
ngx_http_perl_module.
Diffstat (limited to 'src/http/ngx_http_request.c')
-rw-r--r-- | src/http/ngx_http_request.c | 59 |
1 files changed, 36 insertions, 23 deletions
diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c index 5207fa1cc..d8d8936d0 100644 --- a/src/http/ngx_http_request.c +++ b/src/http/ngx_http_request.c @@ -25,7 +25,8 @@ static ngx_int_t ngx_http_process_cookie(ngx_http_request_t *r, ngx_table_elt_t *h, ngx_uint_t offset); static ngx_int_t ngx_http_process_request_header(ngx_http_request_t *r); -static void ngx_http_find_virtual_server(ngx_http_request_t *r); +static void ngx_http_find_virtual_server(ngx_http_request_t *r, + ngx_http_virtual_names_t *vn, ngx_uint_t hash); static void ngx_http_request_handler(ngx_event_t *ev); static ngx_int_t ngx_http_set_write_handler(ngx_http_request_t *r); @@ -739,8 +740,8 @@ ngx_http_process_request_headers(ngx_event_t *rev) { ssize_t n; ngx_int_t rc, rv; - ngx_uint_t key; ngx_str_t header; + ngx_uint_t i; ngx_table_elt_t *h; ngx_connection_t *c; ngx_http_header_t *hh; @@ -763,7 +764,6 @@ ngx_http_process_request_headers(ngx_event_t *rev) cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module); cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); - hh = (ngx_http_header_t *) cmcf->headers_in_hash.buckets; rc = NGX_AGAIN; @@ -841,16 +841,28 @@ ngx_http_process_request_headers(ngx_event_t *rev) h->value.data = r->header_start; h->value.data[h->value.len] = '\0'; - key = h->hash % cmcf->headers_in_hash.hash_size; + h->lowcase_key = ngx_palloc(r->pool, h->key.len); + if (h->lowcase_key == NULL) { + ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); + return; + } - if (hh[key].name.len == h->key.len - && ngx_strcasecmp(hh[key].name.data, h->key.data) == 0) - { - if (hh[key].handler(r, h, hh[key].offset) != NGX_OK) { - return; + if (h->key.len == r->lowcase_index) { + ngx_memcpy(h->lowcase_key, r->lowcase_header, h->key.len); + + } else { + for (i = 0; i < h->key.len; i++) { + h->lowcase_key[i] = ngx_tolower(h->lowcase_key[i]); } } + hh = ngx_hash_find(&cmcf->headers_in_hash, h->hash, + h->lowcase_key, h->key.len); + + if (hh && hh->handler(r, h, hh->offset) != NGX_OK) { + return; + } + ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "http header: \"%V: %V\"", &h->key, &h->value); @@ -1174,12 +1186,16 @@ ngx_http_process_request_header(ngx_http_request_t *r) { size_t len; u_char *ua, *user_agent, ch; + ngx_uint_t hash; #if (NGX_HTTP_SSL) long rc; ngx_http_ssl_srv_conf_t *sscf; #endif if (r->headers_in.host) { + + hash = 0; + for (len = 0; len < r->headers_in.host->value.len; len++) { ch = r->headers_in.host->value.data[len]; @@ -1187,16 +1203,21 @@ ngx_http_process_request_header(ngx_http_request_t *r) break; } - r->headers_in.host->value.data[len] = ngx_tolower(ch); + ch = ngx_tolower(ch); + r->headers_in.host->value.data[len] = ch; + hash = ngx_hash(hash, ch); } - if (r->headers_in.host->value.data[len - 1] == '.') { + if (len && r->headers_in.host->value.data[len - 1] == '.') { len--; + hash = ngx_hash_key(r->headers_in.host->value.data, len); } r->headers_in.host_name_len = len; - ngx_http_find_virtual_server(r); + if (r->virtual_names) { + ngx_http_find_virtual_server(r, r->virtual_names, hash); + } } else { if (r->http_version > NGX_HTTP_VERSION_10) { @@ -1345,27 +1366,19 @@ ngx_http_process_request_header(ngx_http_request_t *r) static void -ngx_http_find_virtual_server(ngx_http_request_t *r) +ngx_http_find_virtual_server(ngx_http_request_t *r, + ngx_http_virtual_names_t *vn, ngx_uint_t hash) { size_t len; u_char *host; - ngx_http_virtual_names_t *vn; ngx_http_core_loc_conf_t *clcf; ngx_http_core_srv_conf_t *cscf; - vn = r->virtual_names; - - if (vn == NULL) { - return; - } - host = r->headers_in.host->value.data; len = r->headers_in.host_name_len; - /* STUB: ngx_hash_key() here is STUB */ - if (vn->hash.buckets) { - cscf = ngx_hash_find(&vn->hash, ngx_hash_key(host, len), host, len); + cscf = ngx_hash_find(&vn->hash, hash, host, len); if (cscf) { goto found; } |