Mercurial > hg > nginx
comparison src/http/ngx_http_request.c @ 437:470270fa84d2
nginx-0.0.12-2004-09-23-20:39:34 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Thu, 23 Sep 2004 16:39:34 +0000 |
parents | 9549fc9508e5 |
children | e56ab5ac8c65 |
comparison
equal
deleted
inserted
replaced
436:9549fc9508e5 | 437:470270fa84d2 |
---|---|
195 return; | 195 return; |
196 } | 196 } |
197 | 197 |
198 hc = c->data; | 198 hc = c->data; |
199 | 199 |
200 if (hc == NULL) { | 200 if (hc) { |
201 | |
202 #if (NGX_STAT_STUB) | |
203 (*ngx_stat_reading)++; | |
204 #endif | |
205 | |
206 } else { | |
201 if (!(hc = ngx_pcalloc(c->pool, sizeof(ngx_http_connection_t)))) { | 207 if (!(hc = ngx_pcalloc(c->pool, sizeof(ngx_http_connection_t)))) { |
202 | 208 |
203 #if (NGX_STAT_STUB) | 209 #if (NGX_STAT_STUB) |
204 (*ngx_stat_reading)--; | 210 (*ngx_stat_reading)--; |
205 #endif | 211 #endif |
217 r->pipeline = hc->pipeline; | 223 r->pipeline = hc->pipeline; |
218 | 224 |
219 if (hc->nbusy) { | 225 if (hc->nbusy) { |
220 r->header_in = hc->busy[0]; | 226 r->header_in = hc->busy[0]; |
221 } | 227 } |
222 | |
223 #if (NGX_STAT_STUB) | |
224 (*ngx_stat_reading)++; | |
225 #endif | |
226 | 228 |
227 } else { | 229 } else { |
228 if (!(r = ngx_pcalloc(c->pool, sizeof(ngx_http_request_t)))) { | 230 if (!(r = ngx_pcalloc(c->pool, sizeof(ngx_http_request_t)))) { |
229 | 231 |
230 #if (NGX_STAT_STUB) | 232 #if (NGX_STAT_STUB) |
681 return; | 683 return; |
682 } | 684 } |
683 | 685 |
684 /* NGX_AGAIN: a request line parsing is still incomplete */ | 686 /* NGX_AGAIN: a request line parsing is still incomplete */ |
685 | 687 |
686 if (r->header_in->last == r->header_in->end) { | 688 if (r->header_in->pos == r->header_in->end) { |
687 | 689 |
688 rv = ngx_http_alloc_large_header_buffer(r, 1); | 690 rv = ngx_http_alloc_large_header_buffer(r, 1); |
689 | 691 |
690 if (rv == NGX_ERROR) { | 692 if (rv == NGX_ERROR) { |
691 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | 693 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); |
726 | 728 |
727 for ( ;; ) { | 729 for ( ;; ) { |
728 | 730 |
729 if (rc == NGX_AGAIN) { | 731 if (rc == NGX_AGAIN) { |
730 | 732 |
731 if (r->header_in->last == r->header_in->end) { | 733 if (r->header_in->pos == r->header_in->end) { |
732 | 734 |
733 rv = ngx_http_alloc_large_header_buffer(r, 0); | 735 rv = ngx_http_alloc_large_header_buffer(r, 0); |
734 | 736 |
735 if (rv == NGX_ERROR) { | 737 if (rv == NGX_ERROR) { |
736 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | 738 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); |
969 hc = r->http_connection; | 971 hc = r->http_connection; |
970 | 972 |
971 if (hc->nfree) { | 973 if (hc->nfree) { |
972 b = hc->free[--hc->nfree]; | 974 b = hc->free[--hc->nfree]; |
973 | 975 |
976 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
977 "http large header free: " PTR_FMT " " SIZE_T_FMT, | |
978 b->pos, b->end - b->last); | |
979 | |
974 } else if (hc->nbusy < cscf->large_client_header_buffers.num) { | 980 } else if (hc->nbusy < cscf->large_client_header_buffers.num) { |
975 | 981 |
976 if (hc->busy == NULL) { | 982 if (hc->busy == NULL) { |
977 hc->busy = ngx_palloc(r->connection->pool, | 983 hc->busy = ngx_palloc(r->connection->pool, |
978 cscf->large_client_header_buffers.num * sizeof(ngx_buf_t *)); | 984 cscf->large_client_header_buffers.num * sizeof(ngx_buf_t *)); |
984 b = ngx_create_temp_buf(r->connection->pool, | 990 b = ngx_create_temp_buf(r->connection->pool, |
985 cscf->large_client_header_buffers.size); | 991 cscf->large_client_header_buffers.size); |
986 if (b == NULL) { | 992 if (b == NULL) { |
987 return NGX_ERROR; | 993 return NGX_ERROR; |
988 } | 994 } |
995 | |
996 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
997 "http large header alloc: " PTR_FMT " " SIZE_T_FMT, | |
998 b->pos, b->end - b->last); | |
989 | 999 |
990 } else { | 1000 } else { |
991 return NGX_DECLINED; | 1001 return NGX_DECLINED; |
992 } | 1002 } |
993 | 1003 |
1003 r->header_in = b; | 1013 r->header_in = b; |
1004 | 1014 |
1005 return NGX_OK; | 1015 return NGX_OK; |
1006 } | 1016 } |
1007 | 1017 |
1018 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
1019 "http large header copy: %d", r->header_in->pos - old); | |
1020 | |
1008 new = b->start; | 1021 new = b->start; |
1009 | 1022 |
1010 ngx_memcpy(new, old, r->header_in->last - old); | 1023 ngx_memcpy(new, old, r->header_in->pos - old); |
1011 | 1024 |
1012 b->pos = new + (r->header_in->pos - old); | 1025 b->pos = new + (r->header_in->pos - old); |
1013 b->last = new + (r->header_in->last - old); | 1026 b->last = new + (r->header_in->pos - old); |
1014 | 1027 |
1015 if (request_line) { | 1028 if (request_line) { |
1016 r->request_start = new; | 1029 r->request_start = new; |
1017 | 1030 |
1018 if (r->request_end) { | 1031 if (r->request_end) { |
1550 ctx->action = "closing request"; | 1563 ctx->action = "closing request"; |
1551 | 1564 |
1552 hc = r->http_connection; | 1565 hc = r->http_connection; |
1553 b = r->header_in; | 1566 b = r->header_in; |
1554 | 1567 |
1555 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | 1568 if (b->pos < b->last) { |
1556 | 1569 |
1557 if (b->pos < b->last || clcf->keepalive_buffers) { | 1570 /* the pipelined request */ |
1558 | |
1559 /* | |
1560 * the pipelined request or we like to keep the allocated | |
1561 * ngx_http_request_t and the client header buffers while keepalive | |
1562 */ | |
1563 | 1571 |
1564 if (b != c->buffer) { | 1572 if (b != c->buffer) { |
1565 | 1573 |
1566 /* move the large header buffers to the free list */ | 1574 /* move the large header buffers to the free list */ |
1567 | 1575 |
1568 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); | 1576 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); |
1569 | 1577 |
1570 if (hc->free == NULL) { | 1578 if (hc->free == NULL) { |
1571 hc->free = ngx_palloc(c->pool, | 1579 hc->free = ngx_palloc(c->pool, |
1572 cscf->large_client_header_buffers.num * sizeof(ngx_buf_t *)); | 1580 cscf->large_client_header_buffers.num * sizeof(ngx_buf_t *)); |
1581 | |
1573 if (hc->free == NULL) { | 1582 if (hc->free == NULL) { |
1574 ngx_http_close_connection(c); | 1583 ngx_http_close_connection(c); |
1575 return; | 1584 return; |
1576 } | 1585 } |
1577 } | 1586 } |
1589 } | 1598 } |
1590 | 1599 |
1591 ngx_http_close_request(r, 0); | 1600 ngx_http_close_request(r, 0); |
1592 c->data = hc; | 1601 c->data = hc; |
1593 | 1602 |
1603 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | |
1594 ngx_add_timer(rev, clcf->keepalive_timeout); | 1604 ngx_add_timer(rev, clcf->keepalive_timeout); |
1595 | 1605 |
1596 if (ngx_handle_level_read_event(rev) == NGX_ERROR) { | 1606 if (ngx_handle_level_read_event(rev) == NGX_ERROR) { |
1597 ngx_http_close_connection(c); | 1607 ngx_http_close_connection(c); |
1598 return; | 1608 return; |
1600 | 1610 |
1601 wev = c->write; | 1611 wev = c->write; |
1602 wev->event_handler = ngx_http_empty_handler; | 1612 wev->event_handler = ngx_http_empty_handler; |
1603 | 1613 |
1604 if (b->pos < b->last) { | 1614 if (b->pos < b->last) { |
1605 | |
1606 /* the pipelined request */ | |
1607 | 1615 |
1608 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "pipelined request"); | 1616 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "pipelined request"); |
1609 | 1617 |
1610 hc->pipeline = 1; | 1618 hc->pipeline = 1; |
1611 ctx->action = "reading client pipelined request line"; | 1619 ctx->action = "reading client pipelined request line"; |
1613 return; | 1621 return; |
1614 } | 1622 } |
1615 | 1623 |
1616 hc->pipeline = 0; | 1624 hc->pipeline = 0; |
1617 | 1625 |
1618 b->pos = b->last = b->start; | 1626 if (ngx_pfree(c->pool, r) == NGX_OK) { |
1619 | 1627 hc->request = NULL; |
1620 if (!clcf->keepalive_buffers) { | 1628 } |
1621 | 1629 |
1622 if (ngx_pfree(c->pool, r) == NGX_OK) { | 1630 b = c->buffer; |
1623 hc->request = NULL; | 1631 |
1624 } | 1632 if (ngx_pfree(c->pool, b->start) == NGX_OK) { |
1625 | 1633 b->pos = NULL; |
1626 if (ngx_pfree(c->pool, c->buffer->start) == NGX_OK) { | 1634 |
1627 c->buffer = NULL; | 1635 } else { |
1628 } | 1636 b->pos = b->start; |
1629 | 1637 b->last = b->start; |
1630 if (hc->free) { | 1638 } |
1631 for (i = 0; i < hc->nfree; i++) { | 1639 |
1632 ngx_pfree(c->pool, hc->free[i]); | 1640 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, "hc free: " PTR_FMT " %d", |
1633 hc->free[i] = NULL; | 1641 hc->free, hc->nfree); |
1634 } | 1642 |
1635 | 1643 if (hc->free) { |
1636 hc->nfree = 0; | 1644 for (i = 0; i < hc->nfree; i++) { |
1637 } | 1645 ngx_pfree(c->pool, hc->free[i]); |
1638 | 1646 hc->free[i] = NULL; |
1639 if (hc->busy) { | 1647 } |
1640 for (i = 0; i < hc->nbusy; i++) { | 1648 |
1641 ngx_pfree(c->pool, hc->busy[i]); | 1649 hc->nfree = 0; |
1642 hc->busy[i] = NULL; | 1650 } |
1643 } | 1651 |
1644 | 1652 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, "hc busy: " PTR_FMT " %d", |
1645 hc->nbusy = 0; | 1653 hc->busy, hc->nbusy); |
1646 } | 1654 |
1655 if (hc->busy) { | |
1656 for (i = 0; i < hc->nbusy; i++) { | |
1657 ngx_pfree(c->pool, hc->busy[i]); | |
1658 hc->busy[i] = NULL; | |
1659 } | |
1660 | |
1661 hc->nbusy = 0; | |
1647 } | 1662 } |
1648 | 1663 |
1649 rev->event_handler = ngx_http_keepalive_handler; | 1664 rev->event_handler = ngx_http_keepalive_handler; |
1650 | 1665 |
1651 if (wev->active) { | 1666 if (wev->active) { |
1687 } | 1702 } |
1688 | 1703 |
1689 | 1704 |
1690 static void ngx_http_keepalive_handler(ngx_event_t *rev) | 1705 static void ngx_http_keepalive_handler(ngx_event_t *rev) |
1691 { | 1706 { |
1707 size_t size; | |
1692 ssize_t n; | 1708 ssize_t n; |
1693 ngx_buf_t *b; | 1709 ngx_buf_t *b; |
1694 ngx_connection_t *c; | 1710 ngx_connection_t *c; |
1695 ngx_http_log_ctx_t *ctx; | 1711 ngx_http_log_ctx_t *ctx; |
1696 ngx_http_connection_t *hc; | 1712 ngx_http_connection_t *hc; |
1702 if (rev->timedout) { | 1718 if (rev->timedout) { |
1703 ngx_http_close_connection(c); | 1719 ngx_http_close_connection(c); |
1704 return; | 1720 return; |
1705 } | 1721 } |
1706 | 1722 |
1723 ctx = (ngx_http_log_ctx_t *) rev->log->data; | |
1724 | |
1725 #if (HAVE_KQUEUE) | |
1726 | |
1727 if (ngx_event_flags & NGX_HAVE_KQUEUE_EVENT) { | |
1728 if (rev->pending_eof) { | |
1729 ngx_log_error(NGX_LOG_INFO, c->log, rev->kq_errno, | |
1730 "kevent() reported that client %s closed " | |
1731 "keepalive connection", ctx->client); | |
1732 ngx_http_close_connection(c); | |
1733 return; | |
1734 } | |
1735 } | |
1736 | |
1737 #endif | |
1738 | |
1707 hc = c->data; | 1739 hc = c->data; |
1708 b = hc->nbusy ? hc->busy[0] : c->buffer; | 1740 b = c->buffer; |
1741 size = b->end - b->start; | |
1742 | |
1743 if (b->pos == NULL) { | |
1744 if (!(b->pos = ngx_palloc(c->pool, size))) { | |
1745 ngx_http_close_connection(c); | |
1746 return; | |
1747 } | |
1748 | |
1749 b->start = b->pos; | |
1750 b->last = b->pos; | |
1751 b->end = b->pos + size; | |
1752 } | |
1709 | 1753 |
1710 /* | 1754 /* |
1711 * MSIE closes a keepalive connection with RST flag | 1755 * MSIE closes a keepalive connection with RST flag |
1712 * so we ignore ECONNRESET here. | 1756 * so we ignore ECONNRESET here. |
1713 */ | 1757 */ |
1714 | 1758 |
1715 c->log_error = NGX_ERROR_IGNORE_ECONNRESET; | 1759 c->log_error = NGX_ERROR_IGNORE_ECONNRESET; |
1716 ngx_set_socket_errno(0); | 1760 ngx_set_socket_errno(0); |
1717 | 1761 |
1718 n = c->recv(c, b->last, b->end - b->last); | 1762 n = c->recv(c, b->last, size); |
1719 c->log_error = NGX_ERROR_INFO; | 1763 c->log_error = NGX_ERROR_INFO; |
1720 | 1764 |
1721 if (n == NGX_AGAIN) { | 1765 if (n == NGX_AGAIN) { |
1722 return; | 1766 return; |
1723 } | 1767 } |
1725 if (n == NGX_ERROR) { | 1769 if (n == NGX_ERROR) { |
1726 ngx_http_close_connection(c); | 1770 ngx_http_close_connection(c); |
1727 return; | 1771 return; |
1728 } | 1772 } |
1729 | 1773 |
1730 ctx = (ngx_http_log_ctx_t *) rev->log->data; | |
1731 rev->log->handler = NULL; | 1774 rev->log->handler = NULL; |
1732 | 1775 |
1733 if (n == 0) { | 1776 if (n == 0) { |
1734 ngx_log_error(NGX_LOG_INFO, c->log, ngx_socket_errno, | 1777 ngx_log_error(NGX_LOG_INFO, c->log, ngx_socket_errno, |
1735 "client %s closed keepalive connection", ctx->client); | 1778 "client %s closed keepalive connection", ctx->client); |