comparison src/event/ngx_event_pipe.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 afceb32f3a8a
children 631ee3c6d38c
comparison
equal deleted inserted replaced
7677:a786e491d08d 7678:bffcc5af1d72
958 958
959 if (buf->pos == buf->last) { 959 if (buf->pos == buf->last) {
960 return NGX_OK; 960 return NGX_OK;
961 } 961 }
962 962
963 if (p->upstream_done) {
964 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, p->log, 0,
965 "input data after close");
966 return NGX_OK;
967 }
968
969 if (p->length == 0) {
970 p->upstream_done = 1;
971
972 ngx_log_error(NGX_LOG_WARN, p->log, 0,
973 "upstream sent more data than specified in "
974 "\"Content-Length\" header");
975
976 return NGX_OK;
977 }
978
963 cl = ngx_chain_get_free_buf(p->pool, &p->free); 979 cl = ngx_chain_get_free_buf(p->pool, &p->free);
964 if (cl == NULL) { 980 if (cl == NULL) {
965 return NGX_ERROR; 981 return NGX_ERROR;
966 } 982 }
967 983
985 1001
986 if (p->length == -1) { 1002 if (p->length == -1) {
987 return NGX_OK; 1003 return NGX_OK;
988 } 1004 }
989 1005
1006 if (b->last - b->pos > p->length) {
1007
1008 ngx_log_error(NGX_LOG_WARN, p->log, 0,
1009 "upstream sent more data than specified in "
1010 "\"Content-Length\" header");
1011
1012 b->last = b->pos + p->length;
1013 p->upstream_done = 1;
1014
1015 return NGX_OK;
1016 }
1017
990 p->length -= b->last - b->pos; 1018 p->length -= b->last - b->pos;
991 1019
992 return NGX_OK; 1020 return NGX_OK;
993 } 1021 }
994 1022