comparison src/http/ngx_http_upstream.c @ 7678:bffcc5af1d72

Upstream: drop extra data sent by upstream. Previous behaviour was to pass everything to the client, but this seems to be suboptimal and causes issues (ticket #1695). Fix is to drop extra data instead, as it naturally happens in most clients. This change covers generic buffered and unbuffered filters as used in the scgi and uwsgi modules. Appropriate input filter init handlers are provided by the scgi and uwsgi modules to set corresponding lengths. Note that for responses to HEAD requests there is an exception: we do allow any response length. This is because responses to HEAD requests might be actual full responses, and it is up to nginx to remove the response body. If caching is enabled, only full responses matching the Content-Length header will be cached (see b779728b180c).
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 06 Jul 2020 18:36:22 +0300
parents 3c8082c3f98a
children 05e42236e95b
comparison
equal deleted inserted replaced
7677:a786e491d08d 7678:bffcc5af1d72
75 ngx_http_upstream_process_non_buffered_upstream(ngx_http_request_t *r, 75 ngx_http_upstream_process_non_buffered_upstream(ngx_http_request_t *r,
76 ngx_http_upstream_t *u); 76 ngx_http_upstream_t *u);
77 static void 77 static void
78 ngx_http_upstream_process_non_buffered_request(ngx_http_request_t *r, 78 ngx_http_upstream_process_non_buffered_request(ngx_http_request_t *r,
79 ngx_uint_t do_write); 79 ngx_uint_t do_write);
80 static ngx_int_t ngx_http_upstream_non_buffered_filter_init(void *data);
81 static ngx_int_t ngx_http_upstream_non_buffered_filter(void *data,
82 ssize_t bytes);
83 #if (NGX_THREADS) 80 #if (NGX_THREADS)
84 static ngx_int_t ngx_http_upstream_thread_handler(ngx_thread_task_t *task, 81 static ngx_int_t ngx_http_upstream_thread_handler(ngx_thread_task_t *task,
85 ngx_file_t *file); 82 ngx_file_t *file);
86 static void ngx_http_upstream_thread_event_handler(ngx_event_t *ev); 83 static void ngx_http_upstream_thread_event_handler(ngx_event_t *ev);
87 #endif 84 #endif
3703 ngx_del_timer(upstream->read); 3700 ngx_del_timer(upstream->read);
3704 } 3701 }
3705 } 3702 }
3706 3703
3707 3704
3708 static ngx_int_t 3705 ngx_int_t
3709 ngx_http_upstream_non_buffered_filter_init(void *data) 3706 ngx_http_upstream_non_buffered_filter_init(void *data)
3710 { 3707 {
3711 return NGX_OK; 3708 return NGX_OK;
3712 } 3709 }
3713 3710
3714 3711
3715 static ngx_int_t 3712 ngx_int_t
3716 ngx_http_upstream_non_buffered_filter(void *data, ssize_t bytes) 3713 ngx_http_upstream_non_buffered_filter(void *data, ssize_t bytes)
3717 { 3714 {
3718 ngx_http_request_t *r = data; 3715 ngx_http_request_t *r = data;
3719 3716
3720 ngx_buf_t *b; 3717 ngx_buf_t *b;
3743 b->last += bytes; 3740 b->last += bytes;
3744 cl->buf->last = b->last; 3741 cl->buf->last = b->last;
3745 cl->buf->tag = u->output.tag; 3742 cl->buf->tag = u->output.tag;
3746 3743
3747 if (u->length == -1) { 3744 if (u->length == -1) {
3745 return NGX_OK;
3746 }
3747
3748 if (bytes > u->length) {
3749
3750 ngx_log_error(NGX_LOG_WARN, r->connection->log, 0,
3751 "upstream sent more data than specified in "
3752 "\"Content-Length\" header");
3753
3754 cl->buf->last = cl->buf->pos + u->length;
3755 u->length = 0;
3756
3748 return NGX_OK; 3757 return NGX_OK;
3749 } 3758 }
3750 3759
3751 u->length -= bytes; 3760 u->length -= bytes;
3752 3761