comparison src/http/ngx_http_request.c @ 633:f971949ffb58 release-0.3.38

nginx-0.3.38-RELEASE import *) Feature: the ngx_http_dav_module. *) Change: the ngx_http_perl_module optimizations. Thanks to Sergey Skvortsov. *) Feature: the ngx_http_perl_module supports the $r->request_body_file method. *) Feature: the "client_body_in_file_only" directive. *) Workaround: now on disk overflow nginx tries to write access logs once a second only. Thanks to Anton Yuzhaninov and Maxim Dounin. *) Bugfix: now the "limit_rate" directive more precisely limits rate if rate is more than 100 Kbyte/s. Thanks to ForJest. *) Bugfix: now the IMAP/POP3 proxy escapes the "\r" and "\n" symbols in login and password to pass authorization server. Thanks to Maxim Dounin.
author Igor Sysoev <igor@sysoev.ru>
date Fri, 14 Apr 2006 09:53:38 +0000
parents 5d2b8078c1c2
children 18268abd340c
comparison
equal deleted inserted replaced
632:5c60f5f0887d 633:f971949ffb58
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 33
34 static void ngx_http_block_read(ngx_http_request_t *r); 34 static void ngx_http_block_read(ngx_http_request_t *r);
35 static void ngx_http_read_discarded_body_handler(ngx_http_request_t *r);
36 static ngx_int_t ngx_http_read_discarded_body(ngx_http_request_t *r);
37
38 static void ngx_http_set_keepalive(ngx_http_request_t *r); 35 static void ngx_http_set_keepalive(ngx_http_request_t *r);
39 static void ngx_http_keepalive_handler(ngx_event_t *ev); 36 static void ngx_http_keepalive_handler(ngx_event_t *ev);
40 static void ngx_http_set_lingering_close(ngx_http_request_t *r); 37 static void ngx_http_set_lingering_close(ngx_http_request_t *r);
41 static void ngx_http_lingering_close_handler(ngx_event_t *ev); 38 static void ngx_http_lingering_close_handler(ngx_event_t *ev);
42 static ngx_int_t ngx_http_post_action(ngx_http_request_t *r); 39 static ngx_int_t ngx_http_post_action(ngx_http_request_t *r);
1680 } 1677 }
1681 } 1678 }
1682 } 1679 }
1683 1680
1684 1681
1685 ngx_int_t
1686 ngx_http_discard_body(ngx_http_request_t *r)
1687 {
1688 ssize_t size;
1689 ngx_event_t *rev;
1690
1691 if (r != r->main) {
1692 return NGX_OK;
1693 }
1694
1695 rev = r->connection->read;
1696
1697 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, rev->log, 0, "http set discard body");
1698
1699 if (rev->timer_set) {
1700 ngx_del_timer(rev);
1701 }
1702
1703 if (r->headers_in.content_length_n <= 0) {
1704 return NGX_OK;
1705 }
1706
1707 r->discard_body = 1;
1708
1709 size = r->header_in->last - r->header_in->pos;
1710
1711 if (size) {
1712 if (r->headers_in.content_length_n > size) {
1713 r->headers_in.content_length_n -= size;
1714
1715 } else {
1716 r->header_in->pos += r->headers_in.content_length_n;
1717 r->headers_in.content_length_n = 0;
1718 return NGX_OK;
1719 }
1720 }
1721
1722 r->read_event_handler = ngx_http_read_discarded_body_handler;
1723
1724 if (ngx_handle_read_event(rev, 0) == NGX_ERROR) {
1725 return NGX_HTTP_INTERNAL_SERVER_ERROR;
1726 }
1727
1728 return ngx_http_read_discarded_body(r);
1729 }
1730
1731
1732 static void
1733 ngx_http_read_discarded_body_handler(ngx_http_request_t *r)
1734 {
1735 ngx_int_t rc;
1736
1737 rc = ngx_http_read_discarded_body(r);
1738
1739 if (rc == NGX_AGAIN) {
1740 if (ngx_handle_read_event(r->connection->read, 0) == NGX_ERROR) {
1741 ngx_http_close_request(r, rc);
1742 return;
1743 }
1744 }
1745
1746 if (rc != NGX_OK) {
1747 ngx_http_close_request(r, rc);
1748 }
1749 }
1750
1751
1752 static ngx_int_t
1753 ngx_http_read_discarded_body(ngx_http_request_t *r)
1754 {
1755 ssize_t size, n;
1756 u_char buffer[NGX_HTTP_DISCARD_BUFFER_SIZE];
1757
1758 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1759 "http read discarded body");
1760
1761 if (r->headers_in.content_length_n == 0) {
1762 return NGX_OK;
1763 }
1764
1765
1766 size = r->headers_in.content_length_n;
1767
1768 if (size > NGX_HTTP_DISCARD_BUFFER_SIZE) {
1769 size = NGX_HTTP_DISCARD_BUFFER_SIZE;
1770 }
1771
1772 n = r->connection->recv(r->connection, buffer, size);
1773
1774 if (n == NGX_ERROR) {
1775
1776 r->connection->error = 1;
1777
1778 /*
1779 * if a client request body is discarded then we already set
1780 * some HTTP response code for client and we can ignore the error
1781 */
1782
1783 return NGX_OK;
1784 }
1785
1786 if (n == NGX_AGAIN) {
1787 return NGX_AGAIN;
1788 }
1789
1790 r->headers_in.content_length_n -= n;
1791
1792 return NGX_OK;
1793 }
1794
1795
1796 static void 1682 static void
1797 ngx_http_set_keepalive(ngx_http_request_t *r) 1683 ngx_http_set_keepalive(ngx_http_request_t *r)
1798 { 1684 {
1799 int tcp_nodelay; 1685 int tcp_nodelay;
1800 ngx_int_t i; 1686 ngx_int_t i;