Mercurial > hg > nginx-mail
comparison src/http/ngx_http_request.c @ 132:91372f004adf NGINX_0_3_13
nginx 0.3.13
*) Feature: the IMAP/POP3 proxy supports STARTTLS and STLS.
*) Bugfix: the IMAP/POP3 proxy did not work with the select, poll, and
/dev/poll methods.
*) Bugfix: in SSI handling.
*) Bugfix: now Solaris sendfilev() is not used to transfer the client
request body to FastCGI-server via the unix domain socket.
*) Bugfix: the "auth_basic" directive did not disable the
authorization; bug appeared in 0.3.11.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Mon, 05 Dec 2005 00:00:00 +0300 |
parents | 82d695e3d662 |
children | 3656228c0b56 |
comparison
equal
deleted
inserted
replaced
131:add6b1e86d38 | 132:91372f004adf |
---|---|
28 static ngx_int_t ngx_http_find_virtual_server(ngx_http_request_t *r); | 28 static ngx_int_t ngx_http_find_virtual_server(ngx_http_request_t *r); |
29 | 29 |
30 static void ngx_http_request_handler(ngx_event_t *ev); | 30 static void ngx_http_request_handler(ngx_event_t *ev); |
31 static ngx_int_t ngx_http_set_write_handler(ngx_http_request_t *r); | 31 static ngx_int_t ngx_http_set_write_handler(ngx_http_request_t *r); |
32 static void ngx_http_writer(ngx_http_request_t *r); | 32 static void ngx_http_writer(ngx_http_request_t *r); |
33 static ngx_int_t ngx_http_postponed_handler(ngx_http_request_t *r); | |
34 | 33 |
35 static void ngx_http_block_read(ngx_http_request_t *r); | 34 static void ngx_http_block_read(ngx_http_request_t *r); |
36 static void ngx_http_read_discarded_body_handler(ngx_http_request_t *r); | 35 static void ngx_http_read_discarded_body_handler(ngx_http_request_t *r); |
37 static ngx_int_t ngx_http_read_discarded_body(ngx_http_request_t *r); | 36 static ngx_int_t ngx_http_read_discarded_body(ngx_http_request_t *r); |
38 | 37 |
402 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); | 401 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); |
403 return; | 402 return; |
404 } | 403 } |
405 | 404 |
406 c->single_connection = 1; | 405 c->single_connection = 1; |
406 c->destroyed = 0; | |
407 | |
407 r->connection = c; | 408 r->connection = c; |
408 | 409 |
409 r->main = r; | 410 r->main = r; |
410 | 411 |
411 r->start_time = ngx_time(); | 412 r->start_time = ngx_time(); |
453 c->timedout = 1; | 454 c->timedout = 1; |
454 ngx_http_close_request(r, NGX_HTTP_REQUEST_TIME_OUT); | 455 ngx_http_close_request(r, NGX_HTTP_REQUEST_TIME_OUT); |
455 return; | 456 return; |
456 } | 457 } |
457 | 458 |
458 n = recv(c->fd, buf, 1, MSG_PEEK); | 459 n = recv(c->fd, (char *) buf, 1, MSG_PEEK); |
459 | 460 |
460 if (n == -1 && ngx_socket_errno == NGX_EAGAIN) { | 461 if (n == -1 && ngx_socket_errno == NGX_EAGAIN) { |
461 return; | 462 return; |
462 } | 463 } |
463 | 464 |
1446 if (rc == NGX_DONE) { | 1447 if (rc == NGX_DONE) { |
1447 /* the request pool may be already destroyed */ | 1448 /* the request pool may be already destroyed */ |
1448 return; | 1449 return; |
1449 } | 1450 } |
1450 | 1451 |
1451 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 1452 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
1452 "http finalize request: %d, \"%V\"", rc, &r->uri); | 1453 "http finalize request: %d, \"%V?%V\"", |
1453 | 1454 rc, &r->uri, &r->args); |
1454 if (rc == NGX_ERROR || r->connection->closed) { | 1455 |
1456 if (rc == NGX_ERROR || r->connection->error) { | |
1455 ngx_http_close_request(r, 0); | 1457 ngx_http_close_request(r, 0); |
1456 return; | 1458 return; |
1457 } | 1459 } |
1458 | 1460 |
1459 if (rc >= NGX_HTTP_SPECIAL_RESPONSE || rc == NGX_HTTP_NO_CONTENT) { | 1461 if (rc >= NGX_HTTP_SPECIAL_RESPONSE || rc == NGX_HTTP_NO_CONTENT) { |
1480 } | 1482 } |
1481 | 1483 |
1482 r->done = 1; | 1484 r->done = 1; |
1483 | 1485 |
1484 if (r != r->connection->data) { | 1486 if (r != r->connection->data) { |
1485 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 1487 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
1486 "http finalize non-active request: \"%V\"", &r->uri); | 1488 "http finalize non-active request: \"%V?%V\"", |
1489 &r->uri, &r->args); | |
1487 return; | 1490 return; |
1488 } | 1491 } |
1489 | 1492 |
1490 if (r->main != r) { | 1493 if (r->main != r) { |
1491 | 1494 |
1492 pr = r->parent; | 1495 pr = r->parent; |
1493 | 1496 |
1494 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 1497 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
1495 "http parent request: \"%V\"", &pr->uri); | 1498 "http parent request: \"%V?%V\"", &pr->uri, &pr->args); |
1496 | 1499 |
1497 if (rc != NGX_AGAIN) { | 1500 if (rc != NGX_AGAIN) { |
1498 pr->connection->data = pr; | 1501 pr->connection->data = pr; |
1499 } | 1502 } |
1500 | 1503 |
1501 if (pr->postponed) { | 1504 if (pr->postponed) { |
1502 | 1505 |
1503 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 1506 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
1504 "http request: \"%V\" has postponed", &pr->uri); | 1507 "http request: \"%V?%V\" has postponed", |
1508 &pr->uri, &pr->args); | |
1505 | 1509 |
1506 if (rc != NGX_AGAIN && pr->postponed->request == r) { | 1510 if (rc != NGX_AGAIN && pr->postponed->request == r) { |
1507 pr->postponed = pr->postponed->next; | 1511 pr->postponed = pr->postponed->next; |
1508 | 1512 |
1509 if (pr->postponed == NULL) { | 1513 if (pr->postponed == NULL) { |
1510 return; | 1514 return; |
1511 } | 1515 } |
1512 } | 1516 } |
1513 | 1517 |
1514 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 1518 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
1515 "http request: \"%V\" still has postponed", | 1519 "http request: \"%V?%V\" still has postponed", |
1516 &pr->uri); | 1520 &pr->uri, &pr->args); |
1517 | 1521 |
1518 if (pr->done) { | 1522 if (pr->done || pr->postponed->out) { |
1519 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 1523 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
1520 "http wake parent request: \"%V\"", &pr->uri); | 1524 "http wake parent request: \"%V?%V\"", |
1525 &pr->uri, &pr->args); | |
1521 | 1526 |
1522 pr->write_event_handler(pr); | 1527 pr->write_event_handler(pr); |
1523 } | 1528 } |
1524 } | 1529 } |
1525 | 1530 |
1617 ngx_http_core_loc_conf_t *clcf; | 1622 ngx_http_core_loc_conf_t *clcf; |
1618 | 1623 |
1619 c = r->connection; | 1624 c = r->connection; |
1620 wev = c->write; | 1625 wev = c->write; |
1621 | 1626 |
1622 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, wev->log, 0, | 1627 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, wev->log, 0, |
1623 "http writer handler: \"%V\"", &r->uri); | 1628 "http writer handler: \"%V?%V\"", &r->uri, &r->args); |
1624 | 1629 |
1625 if (wev->timedout) { | 1630 if (wev->timedout) { |
1626 if (!wev->delayed) { | 1631 if (!wev->delayed) { |
1627 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, | 1632 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, |
1628 "client timed out"); | 1633 "client timed out"); |
1659 | 1664 |
1660 return; | 1665 return; |
1661 } | 1666 } |
1662 } | 1667 } |
1663 | 1668 |
1664 if (r->postponed) { | 1669 rc = ngx_http_output_filter(r, NULL); |
1665 rc = ngx_http_postponed_handler(r); | 1670 |
1666 | 1671 if (c->destroyed) { |
1667 if (rc == NGX_DONE) { | 1672 return; |
1668 /* the request pool may be already destroyed */ | 1673 } |
1669 return; | 1674 |
1670 } | 1675 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, c->log, 0, |
1671 | 1676 "http writer output filter: %d, \"%V?%V\"", |
1672 } else { | 1677 rc, &r->uri, &r->args); |
1673 rc = ngx_http_output_filter(r, NULL); | |
1674 | |
1675 } | |
1676 | |
1677 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
1678 "http writer output filter: %d, \"%V\"", rc, &r->uri); | |
1679 | 1678 |
1680 if (rc == NGX_AGAIN) { | 1679 if (rc == NGX_AGAIN) { |
1681 clcf = ngx_http_get_module_loc_conf(r->main, ngx_http_core_module); | 1680 clcf = ngx_http_get_module_loc_conf(r->main, ngx_http_core_module); |
1682 if (!wev->ready && !wev->delayed) { | 1681 if (!wev->ready && !wev->delayed) { |
1683 ngx_add_timer(wev, clcf->send_timeout); | 1682 ngx_add_timer(wev, clcf->send_timeout); |
1688 } | 1687 } |
1689 | 1688 |
1690 return; | 1689 return; |
1691 } | 1690 } |
1692 | 1691 |
1693 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, wev->log, 0, | 1692 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, wev->log, 0, |
1694 "http writer done: \"%V\"", &r->uri); | 1693 "http writer done: \"%V?%V\"", &r->uri, &r->args); |
1695 | 1694 |
1696 ngx_http_finalize_request(r, rc); | 1695 ngx_http_finalize_request(r, rc); |
1697 } | |
1698 | |
1699 | |
1700 static ngx_int_t | |
1701 ngx_http_postponed_handler(ngx_http_request_t *r) | |
1702 { | |
1703 ngx_int_t rc; | |
1704 ngx_http_postponed_request_t *pr; | |
1705 | |
1706 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
1707 "http postpone handler \"%V\"", &r->uri); | |
1708 | |
1709 pr = r->postponed; | |
1710 | |
1711 if (pr->request == NULL) { | |
1712 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
1713 "http postponed data \"%V\" %p", &r->uri, pr->out); | |
1714 | |
1715 rc = ngx_http_output_filter(r, NULL); | |
1716 | |
1717 if (rc == NGX_DONE) { | |
1718 /* the request pool is already destroyed */ | |
1719 return NGX_DONE; | |
1720 } | |
1721 | |
1722 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
1723 "http postponed output filter: %d", rc); | |
1724 | |
1725 if (rc == NGX_ERROR) { | |
1726 ngx_http_close_request(r, 0); | |
1727 return NGX_DONE; | |
1728 } | |
1729 | |
1730 pr = r->postponed; | |
1731 | |
1732 if (pr == NULL) { | |
1733 | |
1734 if (rc == NGX_AGAIN) { | |
1735 return NGX_AGAIN; | |
1736 } | |
1737 | |
1738 return NGX_OK; | |
1739 } | |
1740 } | |
1741 | |
1742 r = pr->request; | |
1743 r->connection->data = r; | |
1744 | |
1745 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
1746 "http wake child request \"%V\"", &r->uri); | |
1747 | |
1748 r->write_event_handler(r); | |
1749 | |
1750 return NGX_DONE; | |
1751 } | 1696 } |
1752 | 1697 |
1753 | 1698 |
1754 static void | 1699 static void |
1755 ngx_http_block_read(ngx_http_request_t *r) | 1700 ngx_http_block_read(ngx_http_request_t *r) |
1860 | 1805 |
1861 n = r->connection->recv(r->connection, buffer, size); | 1806 n = r->connection->recv(r->connection, buffer, size); |
1862 | 1807 |
1863 if (n == NGX_ERROR) { | 1808 if (n == NGX_ERROR) { |
1864 | 1809 |
1865 r->connection->closed = 1; | 1810 r->connection->error = 1; |
1866 | 1811 |
1867 /* | 1812 /* |
1868 * if a client request body is discarded then we already set | 1813 * if a client request body is discarded then we already set |
1869 * some HTTP response code for client and we can ignore the error | 1814 * some HTTP response code for client and we can ignore the error |
1870 */ | 1815 */ |
2027 hc->nbusy = 0; | 1972 hc->nbusy = 0; |
2028 } | 1973 } |
2029 | 1974 |
2030 rev->handler = ngx_http_keepalive_handler; | 1975 rev->handler = ngx_http_keepalive_handler; |
2031 | 1976 |
2032 if (wev->active) { | 1977 if (wev->active && (ngx_event_flags & NGX_USE_LEVEL_EVENT)) { |
2033 if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) { | 1978 if (ngx_del_event(wev, NGX_WRITE_EVENT, 0) == NGX_ERROR) { |
2034 if (ngx_del_event(wev, NGX_WRITE_EVENT, NGX_DISABLE_EVENT) | 1979 ngx_http_close_connection(c); |
2035 == NGX_ERROR) | 1980 return; |
2036 { | |
2037 ngx_http_close_connection(c); | |
2038 return; | |
2039 } | |
2040 | |
2041 } else if (ngx_event_flags & NGX_USE_LEVEL_EVENT) { | |
2042 if (ngx_del_event(wev, NGX_WRITE_EVENT, 0) == NGX_ERROR) { | |
2043 ngx_http_close_connection(c); | |
2044 return; | |
2045 } | |
2046 } | 1981 } |
2047 } | 1982 } |
2048 | 1983 |
2049 c->log->action = "keepalive"; | 1984 c->log->action = "keepalive"; |
2050 | 1985 |
2222 } | 2157 } |
2223 | 2158 |
2224 wev = c->write; | 2159 wev = c->write; |
2225 wev->handler = ngx_http_empty_handler; | 2160 wev->handler = ngx_http_empty_handler; |
2226 | 2161 |
2227 if (wev->active) { | 2162 if (wev->active && (ngx_event_flags & NGX_USE_LEVEL_EVENT)) { |
2228 if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) { | 2163 if (ngx_del_event(wev, NGX_WRITE_EVENT, 0) == NGX_ERROR) { |
2229 if (ngx_del_event(wev, NGX_WRITE_EVENT, NGX_DISABLE_EVENT) | 2164 ngx_http_close_request(r, 0); |
2230 == NGX_ERROR) | 2165 return; |
2231 { | |
2232 ngx_http_close_request(r, 0); | |
2233 return; | |
2234 } | |
2235 | |
2236 } else if (ngx_event_flags & NGX_USE_LEVEL_EVENT) { | |
2237 if (ngx_del_event(wev, NGX_WRITE_EVENT, 0) == NGX_ERROR) { | |
2238 ngx_http_close_request(r, 0); | |
2239 return; | |
2240 } | |
2241 } | 2166 } |
2242 } | 2167 } |
2243 | 2168 |
2244 if (ngx_shutdown_socket(c->fd, NGX_WRITE_SHUTDOWN) == -1) { | 2169 if (ngx_shutdown_socket(c->fd, NGX_WRITE_SHUTDOWN) == -1) { |
2245 ngx_connection_error(c, ngx_socket_errno, | 2170 ngx_connection_error(c, ngx_socket_errno, |
2322 | 2247 |
2323 void | 2248 void |
2324 ngx_http_request_empty_handler(ngx_http_request_t *r) | 2249 ngx_http_request_empty_handler(ngx_http_request_t *r) |
2325 { | 2250 { |
2326 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 2251 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
2327 "http requets empty handler"); | 2252 "http request empty handler"); |
2328 | 2253 |
2329 return; | 2254 return; |
2330 } | 2255 } |
2331 | 2256 |
2332 | 2257 |
2440 ctx = log->data; | 2365 ctx = log->data; |
2441 ctx->request = NULL; | 2366 ctx->request = NULL; |
2442 | 2367 |
2443 r->request_line.len = 0; | 2368 r->request_line.len = 0; |
2444 | 2369 |
2370 r->connection->destroyed = 1; | |
2371 | |
2445 ngx_destroy_pool(r->pool); | 2372 ngx_destroy_pool(r->pool); |
2446 } | 2373 } |
2447 | 2374 |
2448 | 2375 |
2449 static void | 2376 static void |
2466 #endif | 2393 #endif |
2467 | 2394 |
2468 #if (NGX_STAT_STUB) | 2395 #if (NGX_STAT_STUB) |
2469 ngx_atomic_fetch_add(ngx_stat_active, -1); | 2396 ngx_atomic_fetch_add(ngx_stat_active, -1); |
2470 #endif | 2397 #endif |
2398 | |
2399 c->destroyed = 1; | |
2471 | 2400 |
2472 pool = c->pool; | 2401 pool = c->pool; |
2473 | 2402 |
2474 ngx_close_connection(c); | 2403 ngx_close_connection(c); |
2475 | 2404 |