comparison src/http/ngx_http_request.c @ 32:da8c190bdaba NGINX_0_1_16

nginx 0.1.16 *) Bugfix: if the response were transferred by chunks, then on the HEAD request the final chunk was issued. *) Bugfix: the "Connection: keep-alive" header were issued, even if the keepalive_timeout directive forbade the keep-alive use. *) Bugfix: the errors in the ngx_http_fastcgi_module caused the segmentation faults. *) Bugfix: the compressed response encrypted by SSL may not transferred complete. *) Bugfix: the TCP-specific TCP_NODELAY, TCP_NOPSUH, and TCP_CORK options, are not used for the unix domain sockets. *) Feature: the rewrite directive supports the arguments rewriting. *) Bugfix: the response code 400 was returned for the POST request with the "Content-Length: 0" header; bug appeared in 0.1.14.
author Igor Sysoev <http://sysoev.ru>
date Tue, 25 Jan 2005 00:00:00 +0300
parents 7ca9bdc82b3f
children 2879cd3a40cb
comparison
equal deleted inserted replaced
31:1b17dd824438 32:da8c190bdaba
33 static void ngx_http_set_lingering_close(ngx_http_request_t *r); 33 static void ngx_http_set_lingering_close(ngx_http_request_t *r);
34 static void ngx_http_lingering_close_handler(ngx_event_t *ev); 34 static void ngx_http_lingering_close_handler(ngx_event_t *ev);
35 35
36 static void ngx_http_client_error(ngx_http_request_t *r, 36 static void ngx_http_client_error(ngx_http_request_t *r,
37 int client_error, int error); 37 int client_error, int error);
38 static u_char *ngx_http_log_error(void *data, u_char *buf, size_t len); 38 static u_char *ngx_http_log_error(ngx_log_t *log, u_char *buf, size_t len);
39 39
40 40
41 /* NGX_HTTP_PARSE_... errors */ 41 /* NGX_HTTP_PARSE_... errors */
42 42
43 static char *client_header_errors[] = { 43 static char *client_header_errors[] = {
109 if (!(ctx = ngx_palloc(c->pool, sizeof(ngx_http_log_ctx_t)))) { 109 if (!(ctx = ngx_palloc(c->pool, sizeof(ngx_http_log_ctx_t)))) {
110 ngx_http_close_connection(c); 110 ngx_http_close_connection(c);
111 return; 111 return;
112 } 112 }
113 113
114 ctx->connection = c->number;
115 ctx->client = &c->addr_text; 114 ctx->client = &c->addr_text;
116 ctx->action = "reading client request line";
117 ctx->request = NULL; 115 ctx->request = NULL;
116
117 c->log->connection = c->number;
118 c->log->handler = ngx_http_log_error;
118 c->log->data = ctx; 119 c->log->data = ctx;
119 c->log->handler = ngx_http_log_error; 120 c->log->action = "reading client request line";
121
120 c->log_error = NGX_ERROR_INFO; 122 c->log_error = NGX_ERROR_INFO;
121 123
122 rev = c->read; 124 rev = c->read;
123 rev->event_handler = ngx_http_init_request; 125 rev->event_handler = ngx_http_init_request;
124 126
632 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); 634 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
633 ngx_http_close_connection(c); 635 ngx_http_close_connection(c);
634 return; 636 return;
635 } 637 }
636 638
637 ctx->action = "reading client request headers"; 639 c->log->action = "reading client request headers";
638 640
639 rev->event_handler = ngx_http_process_request_headers; 641 rev->event_handler = ngx_http_process_request_headers;
640 ngx_http_process_request_headers(rev); 642 ngx_http_process_request_headers(rev);
641 643
642 return; 644 return;
1097 if (r->headers_in.content_length_n == NGX_ERROR) { 1099 if (r->headers_in.content_length_n == NGX_ERROR) {
1098 return NGX_HTTP_PARSE_INVALID_CL_HEADER; 1100 return NGX_HTTP_PARSE_INVALID_CL_HEADER;
1099 } 1101 }
1100 } 1102 }
1101 1103
1102 if (r->method == NGX_HTTP_POST && r->headers_in.content_length_n <= 0) { 1104 if (r->method == NGX_HTTP_POST && r->headers_in.content_length_n == -1) {
1103 return NGX_HTTP_PARSE_POST_WO_CL_HEADER; 1105 return NGX_HTTP_PARSE_POST_WO_CL_HEADER;
1104 } 1106 }
1105 1107
1106 if (r->plain_http) { 1108 if (r->plain_http) {
1107 return NGX_HTTP_PARSE_HTTP_TO_HTTPS; 1109 return NGX_HTTP_PARSE_HTTP_TO_HTTPS;
1606 ngx_int_t i; 1608 ngx_int_t i;
1607 ngx_buf_t *b, *f; 1609 ngx_buf_t *b, *f;
1608 ngx_event_t *rev, *wev; 1610 ngx_event_t *rev, *wev;
1609 ngx_connection_t *c; 1611 ngx_connection_t *c;
1610 ngx_http_connection_t *hc; 1612 ngx_http_connection_t *hc;
1611 ngx_http_log_ctx_t *ctx;
1612 ngx_http_core_srv_conf_t *cscf; 1613 ngx_http_core_srv_conf_t *cscf;
1613 ngx_http_core_loc_conf_t *clcf; 1614 ngx_http_core_loc_conf_t *clcf;
1614 1615
1615 c = r->connection; 1616 c = r->connection;
1616 rev = c->read; 1617 rev = c->read;
1617 1618
1618 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "set http keepalive handler"); 1619 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "set http keepalive handler");
1619 1620
1620 ctx = c->log->data; 1621 c->log->action = "closing request";
1621 ctx->action = "closing request";
1622 1622
1623 hc = r->http_connection; 1623 hc = r->http_connection;
1624 b = r->header_in; 1624 b = r->header_in;
1625 1625
1626 if (b->pos < b->last) { 1626 if (b->pos < b->last) {
1680 if (b->pos < b->last) { 1680 if (b->pos < b->last) {
1681 1681
1682 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "pipelined request"); 1682 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "pipelined request");
1683 1683
1684 hc->pipeline = 1; 1684 hc->pipeline = 1;
1685 ctx->action = "reading client pipelined request line"; 1685 c->log->action = "reading client pipelined request line";
1686 ngx_http_init_request(rev); 1686 ngx_http_init_request(rev);
1687 return; 1687 return;
1688 } 1688 }
1689 1689
1690 hc->pipeline = 0; 1690 hc->pipeline = 0;
1758 return; 1758 return;
1759 } 1759 }
1760 } 1760 }
1761 } 1761 }
1762 1762
1763 ctx->action = "keepalive"; 1763 c->log->action = "keepalive";
1764 1764
1765 if (c->tcp_nopush == NGX_TCP_NOPUSH_SET) { 1765 if (c->tcp_nopush == NGX_TCP_NOPUSH_SET) {
1766 if (ngx_tcp_push(c->fd) == NGX_ERROR) { 1766 if (ngx_tcp_push(c->fd) == NGX_ERROR) {
1767 ngx_connection_error(c, ngx_socket_errno, ngx_tcp_push_n " failed"); 1767 ngx_connection_error(c, ngx_socket_errno, ngx_tcp_push_n " failed");
1768 ngx_http_close_connection(c); 1768 ngx_http_close_connection(c);
1774 1774
1775 } else { 1775 } else {
1776 tcp_nodelay = 1; 1776 tcp_nodelay = 1;
1777 } 1777 }
1778 1778
1779 if (tcp_nodelay && clcf->tcp_nodelay && !c->tcp_nodelay) { 1779 if (tcp_nodelay
1780 1780 && clcf->tcp_nodelay
1781 && c->tcp_nodelay == NGX_TCP_NODELAY_UNSET)
1782 {
1781 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "tcp_nodelay"); 1783 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "tcp_nodelay");
1782 1784
1783 if (setsockopt(c->fd, IPPROTO_TCP, TCP_NODELAY, 1785 if (setsockopt(c->fd, IPPROTO_TCP, TCP_NODELAY,
1784 (const void *) &tcp_nodelay, sizeof(int)) == -1) 1786 (const void *) &tcp_nodelay, sizeof(int)) == -1)
1785 { 1787 {
1787 "setsockopt(TCP_NODELAY) failed"); 1789 "setsockopt(TCP_NODELAY) failed");
1788 ngx_http_close_connection(c); 1790 ngx_http_close_connection(c);
1789 return; 1791 return;
1790 } 1792 }
1791 1793
1792 c->tcp_nodelay = 1; 1794 c->tcp_nodelay = NGX_TCP_NODELAY_SET;
1793 } 1795 }
1794 1796
1795 #if 0 1797 #if 0
1796 /* if ngx_http_request_t was freed then we need some other place */ 1798 /* if ngx_http_request_t was freed then we need some other place */
1797 r->http_state = NGX_HTTP_KEEPALIVE_STATE; 1799 r->http_state = NGX_HTTP_KEEPALIVE_STATE;
1807 { 1809 {
1808 size_t size; 1810 size_t size;
1809 ssize_t n; 1811 ssize_t n;
1810 ngx_buf_t *b; 1812 ngx_buf_t *b;
1811 ngx_connection_t *c; 1813 ngx_connection_t *c;
1812 ngx_http_log_ctx_t *ctx;
1813 ngx_http_connection_t *hc; 1814 ngx_http_connection_t *hc;
1814 1815
1815 c = rev->data; 1816 c = rev->data;
1816 1817
1817 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http keepalive handler"); 1818 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http keepalive handler");
1819 if (rev->timedout) { 1820 if (rev->timedout) {
1820 ngx_http_close_connection(c); 1821 ngx_http_close_connection(c);
1821 return; 1822 return;
1822 } 1823 }
1823 1824
1824 ctx = (ngx_http_log_ctx_t *) rev->log->data;
1825
1826 #if (NGX_HAVE_KQUEUE) 1825 #if (NGX_HAVE_KQUEUE)
1827 1826
1828 if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) { 1827 if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) {
1829 if (rev->pending_eof) { 1828 if (rev->pending_eof) {
1830 rev->log->handler = NULL; 1829 c->log->handler = NULL;
1831 ngx_log_error(NGX_LOG_INFO, c->log, rev->kq_errno, 1830 ngx_log_error(NGX_LOG_INFO, c->log, rev->kq_errno,
1832 "kevent() reported that client %V closed " 1831 "kevent() reported that client %V closed "
1833 "keepalive connection", ctx->client); 1832 "keepalive connection", &c->addr_text);
1834 #if (NGX_HTTP_SSL) 1833 #if (NGX_HTTP_SSL)
1835 if (c->ssl) { 1834 if (c->ssl) {
1836 c->ssl->no_send_shut = 1; 1835 c->ssl->no_send_shut = 1;
1837 } 1836 }
1838 #endif 1837 #endif
1887 if (n == NGX_ERROR) { 1886 if (n == NGX_ERROR) {
1888 ngx_http_close_connection(c); 1887 ngx_http_close_connection(c);
1889 return; 1888 return;
1890 } 1889 }
1891 1890
1892 rev->log->handler = NULL; 1891 c->log->handler = NULL;
1893 1892
1894 if (n == 0) { 1893 if (n == 0) {
1895 ngx_log_error(NGX_LOG_INFO, c->log, ngx_socket_errno, 1894 ngx_log_error(NGX_LOG_INFO, c->log, ngx_socket_errno,
1896 "client %V closed keepalive connection", ctx->client); 1895 "client %V closed keepalive connection", &c->addr_text);
1897 ngx_http_close_connection(c); 1896 ngx_http_close_connection(c);
1898 return; 1897 return;
1899 } 1898 }
1900 1899
1901 b->last += n; 1900 b->last += n;
1902 rev->log->handler = ngx_http_log_error; 1901
1903 ctx->action = "reading client request line"; 1902 c->log->handler = ngx_http_log_error;
1903 c->log->action = "reading client request line";
1904 1904
1905 ngx_http_init_request(rev); 1905 ngx_http_init_request(rev);
1906 } 1906 }
1907 1907
1908 1908
2300 2300
2301 ngx_http_finalize_request(r, error); 2301 ngx_http_finalize_request(r, error);
2302 } 2302 }
2303 2303
2304 2304
2305 static u_char *ngx_http_log_error(void *data, u_char *buf, size_t len) 2305 static u_char *ngx_http_log_error(ngx_log_t *log, u_char *buf, size_t len)
2306 { 2306 {
2307 ngx_http_log_ctx_t *ctx = data; 2307 u_char *p;
2308 2308 ngx_http_log_ctx_t *ctx;
2309 u_char *p;
2310 2309
2311 p = buf; 2310 p = buf;
2312 2311
2313 if (ctx->action) { 2312 ctx = log->data;
2314 p = ngx_snprintf(p, len, " while %s", ctx->action); 2313
2314 if (log->action) {
2315 p = ngx_snprintf(p, len, " while %s", log->action);
2315 len -= p - buf; 2316 len -= p - buf;
2316 } 2317 }
2317 2318
2318 p = ngx_snprintf(p, len, ", client: %V", ctx->client); 2319 p = ngx_snprintf(p, len, ", client: %V", ctx->client);
2319 2320