comparison src/http/ngx_http_upstream.c @ 426:e7dbea1ee115 NGINX_0_7_25

nginx 0.7.25 *) Change: in subrequest processing. *) Change: now POSTs without "Content-Length" header line are allowed. *) Bugfix: now the "limit_req" and "limit_conn" directives log a prohibition reason. *) Bugfix: in the "delete" parameter of the "geo" directive.
author Igor Sysoev <http://sysoev.ru>
date Mon, 08 Dec 2008 00:00:00 +0300
parents 9da1d9d94d18
children 21aff1b3da48
comparison
equal deleted inserted replaced
425:f64d9e30046c 426:e7dbea1ee115
272 272
273 273
274 static ngx_http_variable_t ngx_http_upstream_vars[] = { 274 static ngx_http_variable_t ngx_http_upstream_vars[] = {
275 275
276 { ngx_string("upstream_addr"), NULL, 276 { ngx_string("upstream_addr"), NULL,
277 ngx_http_upstream_addr_variable, 0, NGX_HTTP_VAR_NOHASH, 0 }, 277 ngx_http_upstream_addr_variable, 0,
278 NGX_HTTP_VAR_NOHASH|NGX_HTTP_VAR_NOCACHEABLE, 0 },
278 279
279 { ngx_string("upstream_status"), NULL, 280 { ngx_string("upstream_status"), NULL,
280 ngx_http_upstream_status_variable, 0, NGX_HTTP_VAR_NOHASH, 0 }, 281 ngx_http_upstream_status_variable, 0,
282 NGX_HTTP_VAR_NOHASH|NGX_HTTP_VAR_NOCACHEABLE, 0 },
281 283
282 { ngx_string("upstream_response_time"), NULL, 284 { ngx_string("upstream_response_time"), NULL,
283 ngx_http_upstream_response_time_variable, 0, NGX_HTTP_VAR_NOHASH, 0 }, 285 ngx_http_upstream_response_time_variable, 0,
286 NGX_HTTP_VAR_NOHASH|NGX_HTTP_VAR_NOCACHEABLE, 0 },
284 287
285 { ngx_null_string, NULL, NULL, 0, 0, 0 } 288 { ngx_null_string, NULL, NULL, 0, 0, 0 }
286 }; 289 };
287 290
288 291
509 ngx_http_upstream_connect(r, r->upstream); 512 ngx_http_upstream_connect(r, r->upstream);
510 } 513 }
511 514
512 515
513 static void 516 static void
517 ngx_http_upstream_handler(ngx_event_t *ev)
518 {
519 ngx_connection_t *c;
520 ngx_http_request_t *r;
521 ngx_http_log_ctx_t *ctx;
522 ngx_http_upstream_t *u;
523
524 c = ev->data;
525 r = c->data;
526
527 u = r->upstream;
528 c = r->connection;
529
530 ctx = c->log->data;
531 ctx->current_request = r;
532
533 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
534 "http upstream request: \"%V?%V\"", &r->uri, &r->args);
535
536 if (ev->write) {
537 u->write_event_handler(ev);
538
539 } else {
540 u->read_event_handler(ev);
541 }
542
543 ngx_http_run_posted_requests(c);
544 }
545
546
547 static void
514 ngx_http_upstream_rd_check_broken_connection(ngx_http_request_t *r) 548 ngx_http_upstream_rd_check_broken_connection(ngx_http_request_t *r)
515 { 549 {
516 ngx_http_upstream_check_broken_connection(r, r->connection->read); 550 ngx_http_upstream_check_broken_connection(r, r->connection->read);
517 } 551 }
518 552
710 744
711 c = u->peer.connection; 745 c = u->peer.connection;
712 746
713 c->data = r; 747 c->data = r;
714 748
715 c->write->handler = ngx_http_upstream_send_request_handler; 749 c->write->handler = ngx_http_upstream_handler;
716 c->read->handler = ngx_http_upstream_process_header; 750 c->read->handler = ngx_http_upstream_handler;
751
752 u->write_event_handler = ngx_http_upstream_send_request_handler;
753 u->read_event_handler = ngx_http_upstream_process_header;
717 754
718 c->sendfile &= r->connection->sendfile; 755 c->sendfile &= r->connection->sendfile;
719 u->output.sendfile = c->sendfile; 756 u->output.sendfile = c->sendfile;
720 757
721 c->pool = r->pool; 758 c->pool = r->pool;
836 873
837 if (u->conf->ssl_session_reuse) { 874 if (u->conf->ssl_session_reuse) {
838 u->peer.save_session(&u->peer, u->peer.data); 875 u->peer.save_session(&u->peer, u->peer.data);
839 } 876 }
840 877
841 c->write->handler = ngx_http_upstream_send_request_handler; 878 c->write->handler = ngx_http_upstream_handler;
842 c->read->handler = ngx_http_upstream_process_header; 879 c->read->handler = ngx_http_upstream_handler;
843 880
844 ngx_http_upstream_send_request(r, u); 881 ngx_http_upstream_send_request(r, u);
845 882
846 return; 883 return;
847 } 884 }
996 ngx_http_upstream_process_header(c->read); 1033 ngx_http_upstream_process_header(c->read);
997 return; 1034 return;
998 } 1035 }
999 #endif 1036 #endif
1000 1037
1001 c->write->handler = ngx_http_upstream_dummy_handler; 1038 u->write_event_handler = ngx_http_upstream_dummy_handler;
1002 1039
1003 if (ngx_handle_write_event(c->write, 0) == NGX_ERROR) { 1040 if (ngx_handle_write_event(c->write, 0) == NGX_ERROR) {
1004 ngx_http_upstream_finalize_request(r, u, 1041 ngx_http_upstream_finalize_request(r, u,
1005 NGX_HTTP_INTERNAL_SERVER_ERROR); 1042 NGX_HTTP_INTERNAL_SERVER_ERROR);
1006 return; 1043 return;
1035 } 1072 }
1036 1073
1037 #endif 1074 #endif
1038 1075
1039 if (u->header_sent) { 1076 if (u->header_sent) {
1040 wev->handler = ngx_http_upstream_dummy_handler; 1077 u->write_event_handler = ngx_http_upstream_dummy_handler;
1041 1078
1042 (void) ngx_handle_write_event(wev, 0); 1079 (void) ngx_handle_write_event(wev, 0);
1043 1080
1044 return; 1081 return;
1045 } 1082 }
1348 ngx_http_upstream_finalize_request(r, u, 0); 1385 ngx_http_upstream_finalize_request(r, u, 0);
1349 return; 1386 return;
1350 } 1387 }
1351 } 1388 }
1352 1389
1353 rev->handler = ngx_http_upstream_process_body_in_memory; 1390 u->read_event_handler = ngx_http_upstream_process_body_in_memory;
1354 1391
1355 ngx_http_upstream_process_body_in_memory(rev); 1392 ngx_http_upstream_process_body_in_memory(rev);
1356 } 1393 }
1357 1394
1358 1395
1612 u->input_filter_init = ngx_http_upstream_non_buffered_filter_init; 1649 u->input_filter_init = ngx_http_upstream_non_buffered_filter_init;
1613 u->input_filter = ngx_http_upstream_non_buffered_filter; 1650 u->input_filter = ngx_http_upstream_non_buffered_filter;
1614 u->input_filter_ctx = r; 1651 u->input_filter_ctx = r;
1615 } 1652 }
1616 1653
1617 u->peer.connection->read->handler = 1654 u->read_event_handler = ngx_http_upstream_process_non_buffered_body;
1618 ngx_http_upstream_process_non_buffered_body;
1619 r->write_event_handler = 1655 r->write_event_handler =
1620 ngx_http_upstream_process_non_buffered_downstream; 1656 ngx_http_upstream_process_non_buffered_downstream;
1621 1657
1622 r->limit_rate = 0; 1658 r->limit_rate = 0;
1623 1659
1794 1830
1795 p->read_timeout = u->conf->read_timeout; 1831 p->read_timeout = u->conf->read_timeout;
1796 p->send_timeout = clcf->send_timeout; 1832 p->send_timeout = clcf->send_timeout;
1797 p->send_lowat = clcf->send_lowat; 1833 p->send_lowat = clcf->send_lowat;
1798 1834
1799 u->peer.connection->read->handler = ngx_http_upstream_process_body; 1835 u->read_event_handler = ngx_http_upstream_process_body;
1800 r->write_event_handler = ngx_http_upstream_process_downstream; 1836 r->write_event_handler = ngx_http_upstream_process_downstream;
1801 1837
1802 ngx_http_upstream_process_body(u->peer.connection->read); 1838 ngx_http_upstream_process_body(u->peer.connection->read);
1803 } 1839 }
1804 1840
1924 break; 1960 break;
1925 } 1961 }
1926 1962
1927 if (downstream->data == r) { 1963 if (downstream->data == r) {
1928 if (ngx_handle_write_event(downstream->write, clcf->send_lowat) 1964 if (ngx_handle_write_event(downstream->write, clcf->send_lowat)
1929 == NGX_ERROR) 1965 != NGX_OK)
1930 { 1966 {
1931 ngx_http_upstream_finalize_request(r, u, 0); 1967 ngx_http_upstream_finalize_request(r, u, 0);
1932 return; 1968 return;
1933 } 1969 }
1934 } 1970 }
1938 1974
1939 } else if (downstream->write->timer_set) { 1975 } else if (downstream->write->timer_set) {
1940 ngx_del_timer(downstream->write); 1976 ngx_del_timer(downstream->write);
1941 } 1977 }
1942 1978
1943 if (ngx_handle_read_event(upstream->read, 0) == NGX_ERROR) { 1979 if (ngx_handle_read_event(upstream->read, 0) != NGX_OK) {
1944 ngx_http_upstream_finalize_request(r, u, 0); 1980 ngx_http_upstream_finalize_request(r, u, 0);
1945 return; 1981 return;
1946 } 1982 }
1947 1983
1948 if (upstream->read->active && !upstream->read->ready) { 1984 if (upstream->read->active && !upstream->read->ready) {
2014 ngx_http_upstream_process_body(ngx_event_t *ev) 2050 ngx_http_upstream_process_body(ngx_event_t *ev)
2015 { 2051 {
2016 ngx_temp_file_t *tf; 2052 ngx_temp_file_t *tf;
2017 ngx_event_pipe_t *p; 2053 ngx_event_pipe_t *p;
2018 ngx_connection_t *c, *downstream; 2054 ngx_connection_t *c, *downstream;
2019 ngx_http_log_ctx_t *ctx;
2020 ngx_http_request_t *r; 2055 ngx_http_request_t *r;
2021 ngx_http_upstream_t *u; 2056 ngx_http_upstream_t *u;
2022 2057
2023 c = ev->data; 2058 c = ev->data;
2024 r = c->data; 2059 r = c->data;
2032 2067
2033 } else { 2068 } else {
2034 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, 2069 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
2035 "http upstream process upstream"); 2070 "http upstream process upstream");
2036 c->log->action = "reading upstream"; 2071 c->log->action = "reading upstream";
2037
2038 ctx = c->log->data;
2039 ctx->current_request = r;
2040 } 2072 }
2041 2073
2042 p = u->pipe; 2074 p = u->pipe;
2043 2075
2044 if (ev->timedout) { 2076 if (ev->timedout) {
2049 ev->delayed = 0; 2081 ev->delayed = 0;
2050 2082
2051 if (!ev->ready) { 2083 if (!ev->ready) {
2052 ngx_add_timer(ev, p->send_timeout); 2084 ngx_add_timer(ev, p->send_timeout);
2053 2085
2054 if (ngx_handle_write_event(ev, p->send_lowat) == NGX_ERROR) 2086 if (ngx_handle_write_event(ev, p->send_lowat) != NGX_OK) {
2055 {
2056 ngx_http_upstream_finalize_request(r, u, 0); 2087 ngx_http_upstream_finalize_request(r, u, 0);
2057 return; 2088 return;
2058 } 2089 }
2059 2090
2060 return; 2091 return;
2084 } else { 2115 } else {
2085 if (ev->write && ev->delayed) { 2116 if (ev->write && ev->delayed) {
2086 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, 2117 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
2087 "http downstream delayed"); 2118 "http downstream delayed");
2088 2119
2089 if (ngx_handle_write_event(ev, p->send_lowat) == NGX_ERROR) { 2120 if (ngx_handle_write_event(ev, p->send_lowat) != NGX_OK) {
2121 ngx_http_upstream_finalize_request(r, u, 0);
2090 return; 2122 return;
2091 } 2123 }
2092 2124
2093 return; 2125 return;
2094 } 2126 }
2462 return; 2494 return;
2463 } 2495 }
2464 2496
2465 r->connection->log->action = "sending to client"; 2497 r->connection->log->action = "sending to client";
2466 2498
2467 if (rc == 0) { 2499 if (rc == 0 && r == r->main && !r->post_action) {
2468 if (r == r->main) { 2500 rc = ngx_http_send_special(r, NGX_HTTP_LAST);
2469 if (!r->post_action) {
2470 rc = ngx_http_send_special(r, NGX_HTTP_LAST);
2471 }
2472
2473 } else {
2474 if (r->out) {
2475 rc = NGX_AGAIN;
2476 }
2477 }
2478 } 2501 }
2479 2502
2480 ngx_http_finalize_request(r, rc); 2503 ngx_http_finalize_request(r, rc);
2481 } 2504 }
2482 2505