comparison src/http/ngx_http_upstream.c @ 248:acd2ec3541cb NGINX_0_4_9

nginx 0.4.9 *) Feature: the "set" parameter in the "include" SSI command. *) Feature: the ngx_http_perl_module now tests the nginx.pm module version.
author Igor Sysoev <http://sysoev.ru>
date Fri, 13 Oct 2006 00:00:00 +0400
parents 500a3242dff6
children fbf2b2f66c9f
comparison
equal deleted inserted replaced
247:fcca101509a4 248:acd2ec3541cb
19 ngx_http_upstream_t *u); 19 ngx_http_upstream_t *u);
20 static void ngx_http_upstream_send_request(ngx_http_request_t *r, 20 static void ngx_http_upstream_send_request(ngx_http_request_t *r,
21 ngx_http_upstream_t *u); 21 ngx_http_upstream_t *u);
22 static void ngx_http_upstream_send_request_handler(ngx_event_t *wev); 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); 23 static void ngx_http_upstream_process_header(ngx_event_t *rev);
24 static void ngx_http_upstream_process_body_in_memory(ngx_event_t *rev);
24 static void ngx_http_upstream_send_response(ngx_http_request_t *r, 25 static void ngx_http_upstream_send_response(ngx_http_request_t *r,
25 ngx_http_upstream_t *u); 26 ngx_http_upstream_t *u);
26 static void 27 static void
27 ngx_http_upstream_process_non_buffered_downstream(ngx_http_request_t *r); 28 ngx_http_upstream_process_non_buffered_downstream(ngx_http_request_t *r);
28 static void ngx_http_upstream_process_non_buffered_body(ngx_event_t *ev); 29 static void ngx_http_upstream_process_non_buffered_body(ngx_event_t *ev);
1059 return; 1060 return;
1060 } 1061 }
1061 1062
1062 /* rc == NGX_OK */ 1063 /* rc == NGX_OK */
1063 1064
1065 if (u->headers_in.status_n >= NGX_HTTP_BAD_REQUEST
1066 && r->subrequest_in_memory)
1067 {
1068 u->buffer.last = u->buffer.pos;
1069 }
1070
1064 if (u->headers_in.status_n == NGX_HTTP_INTERNAL_SERVER_ERROR) { 1071 if (u->headers_in.status_n == NGX_HTTP_INTERNAL_SERVER_ERROR) {
1065 1072
1066 if (u->peer.tries > 1 1073 if (u->peer.tries > 1
1067 && (u->conf->next_upstream & NGX_HTTP_UPSTREAM_FT_HTTP_500)) 1074 && (u->conf->next_upstream & NGX_HTTP_UPSTREAM_FT_HTTP_500))
1068 { 1075 {
1246 1253
1247 } else { 1254 } else {
1248 u->length = NGX_MAX_SIZE_T_VALUE; 1255 u->length = NGX_MAX_SIZE_T_VALUE;
1249 } 1256 }
1250 1257
1251 ngx_http_upstream_send_response(r, u); 1258 if (!r->subrequest_in_memory) {
1259 ngx_http_upstream_send_response(r, u);
1260 return;
1261 }
1262
1263 /* subrequest content in memory */
1264
1265 if (u->input_filter == NULL) {
1266 u->input_filter_init = ngx_http_upstream_non_buffered_filter_init;
1267 u->input_filter = ngx_http_upstream_non_buffered_filter;
1268 u->input_filter_ctx = r;
1269 }
1270
1271 if (u->input_filter_init(u->input_filter_ctx) == NGX_ERROR) {
1272 ngx_http_upstream_finalize_request(r, u,
1273 NGX_HTTP_INTERNAL_SERVER_ERROR);
1274 return;
1275 }
1276
1277 if (u->buffer.last - u->buffer.pos >= (ssize_t) u->length) {
1278 if (u->input_filter(u->input_filter_ctx, 0) == NGX_ERROR) {
1279 ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
1280 return;
1281 }
1282
1283 ngx_http_upstream_finalize_request(r, u, 0);
1284 return;
1285 }
1286
1287 rev->handler = ngx_http_upstream_process_body_in_memory;
1288
1289 ngx_http_upstream_process_body_in_memory(rev);
1290 }
1291
1292
1293 static void
1294 ngx_http_upstream_process_body_in_memory(ngx_event_t *rev)
1295 {
1296 size_t size;
1297 ssize_t n;
1298 ngx_buf_t *b;
1299 ngx_connection_t *c;
1300 ngx_http_request_t *r;
1301 ngx_http_upstream_t *u;
1302
1303 c = rev->data;
1304 r = c->data;
1305 u = r->upstream;
1306
1307 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
1308 "http upstream process body on memory");
1309
1310 if (rev->timedout) {
1311 ngx_connection_error(c, NGX_ETIMEDOUT, "upstream timed out");
1312 ngx_http_upstream_finalize_request(r, u, NGX_ETIMEDOUT);
1313 return;
1314 }
1315
1316 b = &u->buffer;
1317
1318 for ( ;; ) {
1319
1320 size = b->end - b->last;
1321
1322 if (size == 0) {
1323 ngx_log_error(NGX_LOG_ALERT, c->log, 0,
1324 "upstream buffer is too small to read repsonse");
1325 ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
1326 return;
1327 }
1328
1329 n = c->recv(c, b->last, size);
1330
1331 if (n == NGX_AGAIN) {
1332 break;
1333 }
1334
1335 if (n == 0 || n == NGX_ERROR) {
1336 ngx_http_upstream_finalize_request(r, u, n);
1337 return;
1338 }
1339
1340 if (u->input_filter(u->input_filter_ctx, n) == NGX_ERROR) {
1341 ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
1342 return;
1343 }
1344
1345 if (!rev->ready) {
1346 break;
1347 }
1348 }
1349
1350 if (ngx_handle_read_event(rev, 0) == NGX_ERROR) {
1351 ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
1352 return;
1353 }
1354
1355 if (rev->active) {
1356 ngx_add_timer(rev, u->conf->read_timeout);
1357
1358 } else if (rev->timer_set) {
1359 ngx_del_timer(rev);
1360 }
1252 } 1361 }
1253 1362
1254 1363
1255 static void 1364 static void
1256 ngx_http_upstream_send_response(ngx_http_request_t *r, ngx_http_upstream_t *u) 1365 ngx_http_upstream_send_response(ngx_http_request_t *r, ngx_http_upstream_t *u)