comparison src/http/modules/ngx_http_proxy_module.c @ 6050:a08fad30aeac

Request body: unbuffered reading. The r->request_body_no_buffering flag was introduced. It instructs client request body reading code to avoid reading the whole body, and to call post_handler early instead. The caller should use the ngx_http_read_unbuffered_request_body() function to read remaining parts of the body. Upstream module is now able to use this mode, if configured with the proxy_request_buffering directive.
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 23 Mar 2015 21:09:19 +0300
parents 613b14b305c7
children d97e6be2d292
comparison
equal deleted inserted replaced
6049:42d9beeb22db 6050:a08fad30aeac
290 ngx_conf_set_flag_slot, 290 ngx_conf_set_flag_slot,
291 NGX_HTTP_LOC_CONF_OFFSET, 291 NGX_HTTP_LOC_CONF_OFFSET,
292 offsetof(ngx_http_proxy_loc_conf_t, upstream.buffering), 292 offsetof(ngx_http_proxy_loc_conf_t, upstream.buffering),
293 NULL }, 293 NULL },
294 294
295 { ngx_string("proxy_request_buffering"),
296 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
297 ngx_conf_set_flag_slot,
298 NGX_HTTP_LOC_CONF_OFFSET,
299 offsetof(ngx_http_proxy_loc_conf_t, upstream.request_buffering),
300 NULL },
301
295 { ngx_string("proxy_ignore_client_abort"), 302 { ngx_string("proxy_ignore_client_abort"),
296 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, 303 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
297 ngx_conf_set_flag_slot, 304 ngx_conf_set_flag_slot,
298 NGX_HTTP_LOC_CONF_OFFSET, 305 NGX_HTTP_LOC_CONF_OFFSET,
299 offsetof(ngx_http_proxy_loc_conf_t, upstream.ignore_client_abort), 306 offsetof(ngx_http_proxy_loc_conf_t, upstream.ignore_client_abort),
874 u->input_filter = ngx_http_proxy_non_buffered_copy_filter; 881 u->input_filter = ngx_http_proxy_non_buffered_copy_filter;
875 u->input_filter_ctx = r; 882 u->input_filter_ctx = r;
876 883
877 u->accel = 1; 884 u->accel = 1;
878 885
886 if (!plcf->upstream.request_buffering
887 && plcf->body_values == NULL && plcf->upstream.pass_request_body
888 && !r->headers_in.chunked)
889 {
890 /* TODO: support chunked when using HTTP/1.1 */
891
892 r->request_body_no_buffering = 1;
893 }
894
879 rc = ngx_http_read_client_request_body(r, ngx_http_upstream_init); 895 rc = ngx_http_read_client_request_body(r, ngx_http_upstream_init);
880 896
881 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) { 897 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) {
882 return rc; 898 return rc;
883 } 899 }
1391 1407
1392 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 1408 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1393 "http proxy header:%N\"%*s\"", 1409 "http proxy header:%N\"%*s\"",
1394 (size_t) (b->last - b->pos), b->pos); 1410 (size_t) (b->last - b->pos), b->pos);
1395 1411
1396 if (plcf->body_values == NULL && plcf->upstream.pass_request_body) { 1412 if (r->request_body_no_buffering) {
1413
1414 u->request_bufs = cl;
1415
1416 } else if (plcf->body_values == NULL && plcf->upstream.pass_request_body) {
1397 1417
1398 body = u->request_bufs; 1418 body = u->request_bufs;
1399 u->request_bufs = cl; 1419 u->request_bufs = cl;
1400 1420
1401 while (body) { 1421 while (body) {
2580 2600
2581 conf->upstream.store = NGX_CONF_UNSET; 2601 conf->upstream.store = NGX_CONF_UNSET;
2582 conf->upstream.store_access = NGX_CONF_UNSET_UINT; 2602 conf->upstream.store_access = NGX_CONF_UNSET_UINT;
2583 conf->upstream.next_upstream_tries = NGX_CONF_UNSET_UINT; 2603 conf->upstream.next_upstream_tries = NGX_CONF_UNSET_UINT;
2584 conf->upstream.buffering = NGX_CONF_UNSET; 2604 conf->upstream.buffering = NGX_CONF_UNSET;
2605 conf->upstream.request_buffering = NGX_CONF_UNSET;
2585 conf->upstream.ignore_client_abort = NGX_CONF_UNSET; 2606 conf->upstream.ignore_client_abort = NGX_CONF_UNSET;
2586 conf->upstream.force_ranges = NGX_CONF_UNSET; 2607 conf->upstream.force_ranges = NGX_CONF_UNSET;
2587 2608
2588 conf->upstream.local = NGX_CONF_UNSET_PTR; 2609 conf->upstream.local = NGX_CONF_UNSET_PTR;
2589 2610
2688 ngx_conf_merge_uint_value(conf->upstream.next_upstream_tries, 2709 ngx_conf_merge_uint_value(conf->upstream.next_upstream_tries,
2689 prev->upstream.next_upstream_tries, 0); 2710 prev->upstream.next_upstream_tries, 0);
2690 2711
2691 ngx_conf_merge_value(conf->upstream.buffering, 2712 ngx_conf_merge_value(conf->upstream.buffering,
2692 prev->upstream.buffering, 1); 2713 prev->upstream.buffering, 1);
2714
2715 ngx_conf_merge_value(conf->upstream.request_buffering,
2716 prev->upstream.request_buffering, 1);
2693 2717
2694 ngx_conf_merge_value(conf->upstream.ignore_client_abort, 2718 ngx_conf_merge_value(conf->upstream.ignore_client_abort,
2695 prev->upstream.ignore_client_abort, 0); 2719 prev->upstream.ignore_client_abort, 0);
2696 2720
2697 ngx_conf_merge_value(conf->upstream.force_ranges, 2721 ngx_conf_merge_value(conf->upstream.force_ranges,