comparison src/http/ngx_http_request.c @ 4:4b2dafa26fe2 NGINX_0_1_2

nginx 0.1.2 *) Feature: the --user=USER, --group=GROUP, and --with-ld-opt=OPTIONS options in configure. *) Feature: the server_name directive supports *.domain.tld. *) Bugfix: the portability improvements. *) Bugfix: if configuration file was set in command line, the reconfiguration was impossible; bug appeared in 0.1.1. *) Bugfix: proxy module may get caught in an endless loop when sendfile is not used. *) Bugfix: with sendfile the response was not recoded according to the charset module directives; bug appeared in 0.1.1. *) Bugfix: very seldom bug in the kqueue processing. *) Bugfix: the gzip module compressed the proxied responses that was already compressed.
author Igor Sysoev <http://sysoev.ru>
date Thu, 21 Oct 2004 00:00:00 +0400
parents cc9f381affaa
children 80ba094c6b3e
comparison
equal deleted inserted replaced
3:8beaf7b3241f 4:4b2dafa26fe2
1089 1089
1090 /* find the name based server configuration */ 1090 /* find the name based server configuration */
1091 1091
1092 name = r->virtual_names->elts; 1092 name = r->virtual_names->elts;
1093 for (i = 0; i < r->virtual_names->nelts; i++) { 1093 for (i = 0; i < r->virtual_names->nelts; i++) {
1094 if (r->headers_in.host_name_len != name[i].name.len) { 1094
1095 continue; 1095 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1096 } 1096 "server name: %s", name[i].name.data);
1097 1097
1098 if (ngx_strncasecmp(r->headers_in.host->value.data, 1098 if (name[i].wildcard) {
1099 name[i].name.data, 1099 if (r->headers_in.host_name_len <= name[i].name.len) {
1100 r->headers_in.host_name_len) == 0) 1100 continue;
1101 { 1101 }
1102 r->srv_conf = name[i].core_srv_conf->ctx->srv_conf; 1102
1103 r->loc_conf = name[i].core_srv_conf->ctx->loc_conf; 1103 if (ngx_rstrncasecmp(r->headers_in.host->value.data,
1104 r->server_name = &name[i].name; 1104 name[i].name.data,
1105 1105 name[i].name.len) == 0)
1106 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1107 r->connection->log->file = clcf->err_log->file;
1108 if (!(r->connection->log->log_level & NGX_LOG_DEBUG_CONNECTION))
1109 { 1106 {
1110 r->connection->log->log_level = clcf->err_log->log_level; 1107 continue;
1111 } 1108 }
1112 1109
1113 break; 1110 } else {
1114 } 1111 if (r->headers_in.host_name_len != name[i].name.len) {
1112 continue;
1113 }
1114
1115 if (ngx_strncasecmp(r->headers_in.host->value.data,
1116 name[i].name.data,
1117 name[i].name.len) != 0)
1118 {
1119 continue;
1120 }
1121 }
1122
1123 r->srv_conf = name[i].core_srv_conf->ctx->srv_conf;
1124 r->loc_conf = name[i].core_srv_conf->ctx->loc_conf;
1125 r->server_name = &name[i].name;
1126
1127 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1128 r->connection->log->file = clcf->err_log->file;
1129
1130 if (!(r->connection->log->log_level & NGX_LOG_DEBUG_CONNECTION)) {
1131 r->connection->log->log_level = clcf->err_log->log_level;
1132 }
1133
1134 break;
1115 } 1135 }
1116 1136
1117 if (i == r->virtual_names->nelts) { 1137 if (i == r->virtual_names->nelts) {
1118 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); 1138 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
1119 1139
1560 1580
1561 /* the pipelined request */ 1581 /* the pipelined request */
1562 1582
1563 if (b != c->buffer) { 1583 if (b != c->buffer) {
1564 1584
1565 /* move the large header buffers to the free list */ 1585 /*
1586 * If the large header buffers were allocated while the previous
1587 * request processing then we do not use c->buffer for
1588 * the pipelined request (see ngx_http_init_request()).
1589 *
1590 * Now we would move the large header buffers to the free list.
1591 */
1566 1592
1567 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); 1593 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
1568 1594
1569 if (hc->free == NULL) { 1595 if (hc->free == NULL) {
1570 hc->free = ngx_palloc(c->pool, 1596 hc->free = ngx_palloc(c->pool,
1612 return; 1638 return;
1613 } 1639 }
1614 1640
1615 hc->pipeline = 0; 1641 hc->pipeline = 0;
1616 1642
1643 /*
1644 * To keep a memory footprint as small as possible for an idle
1645 * keepalive connection we try to free the ngx_http_request_t and
1646 * c->buffer's memory if they were allocated outside the c->pool.
1647 * The large header buffers are always allocated outside the c->pool and
1648 * are freed too.
1649 */
1650
1617 if (ngx_pfree(c->pool, r) == NGX_OK) { 1651 if (ngx_pfree(c->pool, r) == NGX_OK) {
1618 hc->request = NULL; 1652 hc->request = NULL;
1619 } 1653 }
1620 1654
1621 b = c->buffer; 1655 b = c->buffer;
1622 1656
1623 if (ngx_pfree(c->pool, b->start) == NGX_OK) { 1657 if (ngx_pfree(c->pool, b->start) == NGX_OK) {
1658
1659 /*
1660 * the special note for ngx_http_keepalive_handler() that
1661 * c->buffer's memory was freed
1662 */
1663
1624 b->pos = NULL; 1664 b->pos = NULL;
1625 1665
1626 } else { 1666 } else {
1627 b->pos = b->start; 1667 b->pos = b->start;
1628 b->last = b->start; 1668 b->last = b->start;
1653 } 1693 }
1654 1694
1655 rev->event_handler = ngx_http_keepalive_handler; 1695 rev->event_handler = ngx_http_keepalive_handler;
1656 1696
1657 if (wev->active) { 1697 if (wev->active) {
1658 if (ngx_event_flags & NGX_HAVE_KQUEUE_EVENT) { 1698 if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) {
1659 if (ngx_del_event(wev, NGX_WRITE_EVENT, NGX_DISABLE_EVENT) 1699 if (ngx_del_event(wev, NGX_WRITE_EVENT, NGX_DISABLE_EVENT)
1660 == NGX_ERROR) 1700 == NGX_ERROR)
1661 { 1701 {
1662 ngx_http_close_connection(c); 1702 ngx_http_close_connection(c);
1663 return; 1703 return;
1700 c->tcp_nodelay = 1; 1740 c->tcp_nodelay = 1;
1701 } 1741 }
1702 } 1742 }
1703 1743
1704 #if 0 1744 #if 0
1705 /* if "keepalive_buffers off" then we need some other place */ 1745 /* if ngx_http_request_t was freed then we need some other place */
1706 r->http_state = NGX_HTTP_KEEPALIVE_STATE; 1746 r->http_state = NGX_HTTP_KEEPALIVE_STATE;
1707 #endif 1747 #endif
1708 1748
1709 if (rev->ready) { 1749 if (rev->ready) {
1710 ngx_http_keepalive_handler(rev); 1750 ngx_http_keepalive_handler(rev);
1732 1772
1733 ctx = (ngx_http_log_ctx_t *) rev->log->data; 1773 ctx = (ngx_http_log_ctx_t *) rev->log->data;
1734 1774
1735 #if (HAVE_KQUEUE) 1775 #if (HAVE_KQUEUE)
1736 1776
1737 if (ngx_event_flags & NGX_HAVE_KQUEUE_EVENT) { 1777 if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) {
1738 if (rev->pending_eof) { 1778 if (rev->pending_eof) {
1739 ngx_log_error(NGX_LOG_INFO, c->log, rev->kq_errno, 1779 ngx_log_error(NGX_LOG_INFO, c->log, rev->kq_errno,
1740 "kevent() reported that client %s closed " 1780 "kevent() reported that client %s closed "
1741 "keepalive connection", ctx->client); 1781 "keepalive connection", ctx->client);
1742 ngx_http_close_connection(c); 1782 ngx_http_close_connection(c);
1749 hc = c->data; 1789 hc = c->data;
1750 b = c->buffer; 1790 b = c->buffer;
1751 size = b->end - b->start; 1791 size = b->end - b->start;
1752 1792
1753 if (b->pos == NULL) { 1793 if (b->pos == NULL) {
1794
1795 /*
1796 * The c->buffer's memory was freed by ngx_http_set_keepalive().
1797 * However, the c->buffer->start and c->buffer->end were not changed
1798 * to keep the buffer size.
1799 */
1800
1754 if (!(b->pos = ngx_palloc(c->pool, size))) { 1801 if (!(b->pos = ngx_palloc(c->pool, size))) {
1755 ngx_http_close_connection(c); 1802 ngx_http_close_connection(c);
1756 return; 1803 return;
1757 } 1804 }
1758 1805
1822 1869
1823 wev = c->write; 1870 wev = c->write;
1824 wev->event_handler = ngx_http_empty_handler; 1871 wev->event_handler = ngx_http_empty_handler;
1825 1872
1826 if (wev->active) { 1873 if (wev->active) {
1827 if (ngx_event_flags & NGX_HAVE_KQUEUE_EVENT) { 1874 if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) {
1828 if (ngx_del_event(wev, NGX_WRITE_EVENT, NGX_DISABLE_EVENT) 1875 if (ngx_del_event(wev, NGX_WRITE_EVENT, NGX_DISABLE_EVENT)
1829 == NGX_ERROR) 1876 == NGX_ERROR)
1830 { 1877 {
1831 ngx_http_close_connection(c); 1878 ngx_http_close_connection(c);
1832 return; 1879 return;