19 | 19 |
ngx_http_upstream_t *u);
|
20 | 20 |
static void ngx_http_upstream_send_request(ngx_http_request_t *r,
|
21 | 21 |
ngx_http_upstream_t *u);
|
22 | |
static void ngx_http_upstream_send_request_handler(ngx_event_t *wev);
|
23 | |
static void ngx_http_upstream_process_header(ngx_event_t *rev);
|
|
22 |
static void ngx_http_upstream_send_request_handler(ngx_http_request_t *r,
|
|
23 |
ngx_http_upstream_t *u);
|
|
24 |
static void ngx_http_upstream_process_header(ngx_http_request_t *r,
|
|
25 |
ngx_http_upstream_t *u);
|
24 | 26 |
static ngx_int_t ngx_http_upstream_test_next(ngx_http_request_t *r,
|
25 | 27 |
ngx_http_upstream_t *u);
|
26 | 28 |
static ngx_int_t ngx_http_upstream_intercept_errors(ngx_http_request_t *r,
|
27 | 29 |
ngx_http_upstream_t *u);
|
28 | 30 |
static ngx_int_t ngx_http_upstream_test_connect(ngx_connection_t *c);
|
29 | |
static void ngx_http_upstream_process_body_in_memory(ngx_event_t *rev);
|
|
31 |
static void ngx_http_upstream_process_body_in_memory(ngx_http_request_t *r,
|
|
32 |
ngx_http_upstream_t *u);
|
30 | 33 |
static void ngx_http_upstream_send_response(ngx_http_request_t *r,
|
31 | 34 |
ngx_http_upstream_t *u);
|
32 | 35 |
static void
|
33 | 36 |
ngx_http_upstream_process_non_buffered_downstream(ngx_http_request_t *r);
|
34 | |
static void ngx_http_upstream_process_non_buffered_upstream(ngx_event_t *ev);
|
|
37 |
static void
|
|
38 |
ngx_http_upstream_process_non_buffered_upstream(ngx_http_request_t *r,
|
|
39 |
ngx_http_upstream_t *u);
|
35 | 40 |
static void
|
36 | 41 |
ngx_http_upstream_process_non_buffered_request(ngx_http_request_t *r,
|
37 | 42 |
ngx_uint_t do_write);
|
|
39 | 44 |
static ngx_int_t ngx_http_upstream_non_buffered_filter(void *data,
|
40 | 45 |
ssize_t bytes);
|
41 | 46 |
static void ngx_http_upstream_process_downstream(ngx_http_request_t *r);
|
42 | |
static void ngx_http_upstream_process_upstream(ngx_event_t *rev);
|
|
47 |
static void ngx_http_upstream_process_upstream(ngx_http_request_t *r,
|
|
48 |
ngx_http_upstream_t *u);
|
43 | 49 |
static void ngx_http_upstream_process_request(ngx_http_request_t *r);
|
44 | 50 |
static void ngx_http_upstream_store(ngx_http_request_t *r,
|
45 | 51 |
ngx_http_upstream_t *u);
|
46 | |
static void ngx_http_upstream_dummy_handler(ngx_event_t *wev);
|
|
52 |
static void ngx_http_upstream_dummy_handler(ngx_http_request_t *r,
|
|
53 |
ngx_http_upstream_t *u);
|
47 | 54 |
static void ngx_http_upstream_next(ngx_http_request_t *r,
|
48 | 55 |
ngx_http_upstream_t *u, ngx_uint_t ft_type);
|
49 | 56 |
static void ngx_http_upstream_cleanup(void *data);
|
|
537 | 544 |
"http upstream request: \"%V?%V\"", &r->uri, &r->args);
|
538 | 545 |
|
539 | 546 |
if (ev->write) {
|
540 | |
u->write_event_handler(ev);
|
|
547 |
u->write_event_handler(r, u);
|
541 | 548 |
|
542 | 549 |
} else {
|
543 | |
u->read_event_handler(ev);
|
|
550 |
u->read_event_handler(r, u);
|
544 | 551 |
}
|
545 | 552 |
|
546 | 553 |
ngx_http_run_posted_requests(c);
|
|
995 | 1002 |
if (rc == NGX_AGAIN) {
|
996 | 1003 |
ngx_add_timer(c->write, u->conf->send_timeout);
|
997 | 1004 |
|
998 | |
if (ngx_handle_write_event(c->write, u->conf->send_lowat) == NGX_ERROR)
|
999 | |
{
|
|
1005 |
if (ngx_handle_write_event(c->write, u->conf->send_lowat) != NGX_OK) {
|
1000 | 1006 |
ngx_http_upstream_finalize_request(r, u,
|
1001 | 1007 |
NGX_HTTP_INTERNAL_SERVER_ERROR);
|
1002 | 1008 |
return;
|
|
1033 | 1039 |
* it's better to do here because we postpone header buffer allocation
|
1034 | 1040 |
*/
|
1035 | 1041 |
|
1036 | |
ngx_http_upstream_process_header(c->read);
|
|
1042 |
ngx_http_upstream_process_header(r, u);
|
1037 | 1043 |
return;
|
1038 | 1044 |
}
|
1039 | 1045 |
#endif
|
1040 | 1046 |
|
1041 | 1047 |
u->write_event_handler = ngx_http_upstream_dummy_handler;
|
1042 | 1048 |
|
1043 | |
if (ngx_handle_write_event(c->write, 0) == NGX_ERROR) {
|
|
1049 |
if (ngx_handle_write_event(c->write, 0) != NGX_OK) {
|
1044 | 1050 |
ngx_http_upstream_finalize_request(r, u,
|
1045 | 1051 |
NGX_HTTP_INTERNAL_SERVER_ERROR);
|
1046 | 1052 |
return;
|
|
1049 | 1055 |
|
1050 | 1056 |
|
1051 | 1057 |
static void
|
1052 | |
ngx_http_upstream_send_request_handler(ngx_event_t *wev)
|
1053 | |
{
|
1054 | |
ngx_connection_t *c;
|
1055 | |
ngx_http_request_t *r;
|
1056 | |
ngx_http_upstream_t *u;
|
1057 | |
|
1058 | |
c = wev->data;
|
1059 | |
r = c->data;
|
1060 | |
u = r->upstream;
|
1061 | |
|
1062 | |
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, wev->log, 0,
|
|
1058 |
ngx_http_upstream_send_request_handler(ngx_http_request_t *r,
|
|
1059 |
ngx_http_upstream_t *u)
|
|
1060 |
{
|
|
1061 |
ngx_connection_t *c;
|
|
1062 |
|
|
1063 |
c = u->peer.connection;
|
|
1064 |
|
|
1065 |
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
1063 | 1066 |
"http upstream send request handler");
|
1064 | 1067 |
|
1065 | |
if (wev->timedout) {
|
|
1068 |
if (c->write->timedout) {
|
1066 | 1069 |
ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_TIMEOUT);
|
1067 | 1070 |
return;
|
1068 | 1071 |
}
|
|
1079 | 1082 |
if (u->header_sent) {
|
1080 | 1083 |
u->write_event_handler = ngx_http_upstream_dummy_handler;
|
1081 | 1084 |
|
1082 | |
(void) ngx_handle_write_event(wev, 0);
|
|
1085 |
(void) ngx_handle_write_event(c->write, 0);
|
1083 | 1086 |
|
1084 | 1087 |
return;
|
1085 | 1088 |
}
|
|
1089 | 1092 |
|
1090 | 1093 |
|
1091 | 1094 |
static void
|
1092 | |
ngx_http_upstream_process_header(ngx_event_t *rev)
|
|
1095 |
ngx_http_upstream_process_header(ngx_http_request_t *r, ngx_http_upstream_t *u)
|
1093 | 1096 |
{
|
1094 | 1097 |
ssize_t n;
|
1095 | 1098 |
ngx_int_t rc;
|
|
1098 | 1101 |
ngx_list_part_t *part;
|
1099 | 1102 |
ngx_table_elt_t *h;
|
1100 | 1103 |
ngx_connection_t *c;
|
1101 | |
ngx_http_request_t *r;
|
1102 | |
ngx_http_upstream_t *u;
|
1103 | 1104 |
ngx_http_upstream_header_t *hh;
|
1104 | 1105 |
ngx_http_upstream_main_conf_t *umcf;
|
1105 | 1106 |
|
1106 | |
c = rev->data;
|
1107 | |
r = c->data;
|
1108 | |
u = r->upstream;
|
1109 | |
|
1110 | |
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, rev->log, 0,
|
|
1107 |
c = u->peer.connection;
|
|
1108 |
|
|
1109 |
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
|
1111 | 1110 |
"http upstream process header");
|
1112 | 1111 |
|
1113 | 1112 |
c->log->action = "reading response header from upstream";
|
1114 | 1113 |
|
1115 | |
if (rev->timedout) {
|
|
1114 |
if (c->read->timedout) {
|
1116 | 1115 |
ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_TIMEOUT);
|
1117 | 1116 |
return;
|
1118 | 1117 |
}
|
|
1163 | 1162 |
ngx_add_timer(rev, u->read_timeout);
|
1164 | 1163 |
#endif
|
1165 | 1164 |
|
1166 | |
if (ngx_handle_read_event(rev, 0) == NGX_ERROR) {
|
|
1165 |
if (ngx_handle_read_event(c->read, 0) != NGX_OK) {
|
1167 | 1166 |
ngx_http_upstream_finalize_request(r, u,
|
1168 | 1167 |
NGX_HTTP_INTERNAL_SERVER_ERROR);
|
1169 | 1168 |
return;
|
|
1173 | 1172 |
}
|
1174 | 1173 |
|
1175 | 1174 |
if (n == 0) {
|
1176 | |
ngx_log_error(NGX_LOG_ERR, rev->log, 0,
|
|
1175 |
ngx_log_error(NGX_LOG_ERR, c->log, 0,
|
1177 | 1176 |
"upstream prematurely closed connection");
|
1178 | 1177 |
}
|
1179 | 1178 |
|
|
1195 | 1194 |
if (rc == NGX_AGAIN) {
|
1196 | 1195 |
|
1197 | 1196 |
if (u->buffer.pos == u->buffer.end) {
|
1198 | |
ngx_log_error(NGX_LOG_ERR, rev->log, 0,
|
|
1197 |
ngx_log_error(NGX_LOG_ERR, c->log, 0,
|
1199 | 1198 |
"upstream sent too big header");
|
1200 | 1199 |
|
1201 | 1200 |
ngx_http_upstream_next(r, u,
|
|
1392 | 1391 |
|
1393 | 1392 |
u->read_event_handler = ngx_http_upstream_process_body_in_memory;
|
1394 | 1393 |
|
1395 | |
ngx_http_upstream_process_body_in_memory(rev);
|
|
1394 |
ngx_http_upstream_process_body_in_memory(r, u);
|
1396 | 1395 |
}
|
1397 | 1396 |
|
1398 | 1397 |
|
|
1536 | 1535 |
|
1537 | 1536 |
|
1538 | 1537 |
static void
|
1539 | |
ngx_http_upstream_process_body_in_memory(ngx_event_t *rev)
|
1540 | |
{
|
1541 | |
size_t size;
|
1542 | |
ssize_t n;
|
1543 | |
ngx_buf_t *b;
|
1544 | |
ngx_connection_t *c;
|
1545 | |
ngx_http_request_t *r;
|
1546 | |
ngx_http_upstream_t *u;
|
1547 | |
|
1548 | |
c = rev->data;
|
1549 | |
r = c->data;
|
1550 | |
u = r->upstream;
|
|
1538 |
ngx_http_upstream_process_body_in_memory(ngx_http_request_t *r,
|
|
1539 |
ngx_http_upstream_t *u)
|
|
1540 |
{
|
|
1541 |
size_t size;
|
|
1542 |
ssize_t n;
|
|
1543 |
ngx_buf_t *b;
|
|
1544 |
ngx_event_t *rev;
|
|
1545 |
ngx_connection_t *c;
|
|
1546 |
|
|
1547 |
c = u->peer.connection;
|
|
1548 |
rev = c->read;
|
1551 | 1549 |
|
1552 | 1550 |
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
|
1553 | 1551 |
"http upstream process body on memory");
|
|
1592 | 1590 |
}
|
1593 | 1591 |
}
|
1594 | 1592 |
|
1595 | |
if (ngx_handle_read_event(rev, 0) == NGX_ERROR) {
|
|
1593 |
if (ngx_handle_read_event(rev, 0) != NGX_OK) {
|
1596 | 1594 |
ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
|
1597 | 1595 |
return;
|
1598 | 1596 |
}
|
|
1704 | 1702 |
}
|
1705 | 1703 |
|
1706 | 1704 |
if (u->peer.connection->read->ready) {
|
1707 | |
ngx_http_upstream_process_non_buffered_upstream(
|
1708 | |
u->peer.connection->read);
|
|
1705 |
ngx_http_upstream_process_non_buffered_upstream(r, u);
|
1709 | 1706 |
}
|
1710 | 1707 |
}
|
1711 | 1708 |
|
|
1838 | 1835 |
u->read_event_handler = ngx_http_upstream_process_upstream;
|
1839 | 1836 |
r->write_event_handler = ngx_http_upstream_process_downstream;
|
1840 | 1837 |
|
1841 | |
ngx_http_upstream_process_upstream(u->peer.connection->read);
|
|
1838 |
ngx_http_upstream_process_upstream(r, u);
|
1842 | 1839 |
}
|
1843 | 1840 |
|
1844 | 1841 |
|
|
1870 | 1867 |
|
1871 | 1868 |
|
1872 | 1869 |
static void
|
1873 | |
ngx_http_upstream_process_non_buffered_upstream(ngx_event_t *rev)
|
1874 | |
{
|
1875 | |
ngx_connection_t *c;
|
1876 | |
ngx_http_request_t *r;
|
1877 | |
ngx_http_upstream_t *u;
|
1878 | |
|
1879 | |
c = rev->data;
|
1880 | |
r = c->data;
|
1881 | |
u = r->upstream;
|
|
1870 |
ngx_http_upstream_process_non_buffered_upstream(ngx_http_request_t *r,
|
|
1871 |
ngx_http_upstream_t *u)
|
|
1872 |
{
|
|
1873 |
ngx_connection_t *c;
|
|
1874 |
|
|
1875 |
c = u->peer.connection;
|
1882 | 1876 |
|
1883 | 1877 |
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
|
1884 | 1878 |
"http upstream process non buffered upstream");
|
1885 | 1879 |
|
1886 | 1880 |
c->log->action = "reading upstream";
|
1887 | 1881 |
|
1888 | |
if (rev->timedout) {
|
|
1882 |
if (c->read->timedout) {
|
1889 | 1883 |
ngx_connection_error(c, NGX_ETIMEDOUT, "upstream timed out");
|
1890 | 1884 |
ngx_http_upstream_finalize_request(r, u, 0);
|
1891 | 1885 |
return;
|
|
2141 | 2135 |
|
2142 | 2136 |
|
2143 | 2137 |
static void
|
2144 | |
ngx_http_upstream_process_upstream(ngx_event_t *rev)
|
2145 | |
{
|
2146 | |
ngx_connection_t *c;
|
2147 | |
ngx_event_pipe_t *p;
|
2148 | |
ngx_http_request_t *r;
|
2149 | |
ngx_http_upstream_t *u;
|
2150 | |
|
2151 | |
c = rev->data;
|
2152 | |
r = c->data;
|
2153 | |
u = r->upstream;
|
2154 | |
p = u->pipe;
|
|
2138 |
ngx_http_upstream_process_upstream(ngx_http_request_t *r,
|
|
2139 |
ngx_http_upstream_t *u)
|
|
2140 |
{
|
|
2141 |
ngx_connection_t *c;
|
|
2142 |
|
|
2143 |
c = u->peer.connection;
|
2155 | 2144 |
|
2156 | 2145 |
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
|
2157 | 2146 |
"http upstream process upstream");
|
2158 | 2147 |
|
2159 | 2148 |
c->log->action = "reading upstream";
|
2160 | 2149 |
|
2161 | |
if (rev->timedout) {
|
2162 | |
p->upstream_error = 1;
|
|
2150 |
if (c->read->timedout) {
|
|
2151 |
u->pipe->upstream_error = 1;
|
2163 | 2152 |
ngx_connection_error(c, NGX_ETIMEDOUT, "upstream timed out");
|
2164 | 2153 |
|
2165 | 2154 |
} else {
|
2166 | 2155 |
c = r->connection;
|
2167 | 2156 |
|
2168 | |
if (ngx_event_pipe(p, 0) == NGX_ABORT) {
|
|
2157 |
if (ngx_event_pipe(u->pipe, 0) == NGX_ABORT) {
|
2169 | 2158 |
|
2170 | 2159 |
if (c->destroyed) {
|
2171 | 2160 |
return;
|
|
2336 | 2325 |
|
2337 | 2326 |
|
2338 | 2327 |
static void
|
2339 | |
ngx_http_upstream_dummy_handler(ngx_event_t *wev)
|
2340 | |
{
|
2341 | |
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, wev->log, 0,
|
|
2328 |
ngx_http_upstream_dummy_handler(ngx_http_request_t *r, ngx_http_upstream_t *u)
|
|
2329 |
{
|
|
2330 |
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
2342 | 2331 |
"http upstream dummy handler");
|
2343 | 2332 |
}
|
2344 | 2333 |
|