comparison src/http/ngx_http_core_module.c @ 8124:f5515e727656

Fixed "zero size buf" alerts with subrequests. Since 4611:2b6cb7528409 responses from the gzip static, flv, and mp4 modules can be used with subrequests, though empty files were not properly handled. Empty gzipped, flv, and mp4 files thus resulted in "zero size buf in output" alerts. While valid corresponding files are not expected to be empty, such files shouldn't result in alerts. Fix is to set b->sync on such empty subrequest responses, similarly to what ngx_http_send_special() does. Additionally, the static module, the ngx_http_send_response() function, and file cache are modified to do the same instead of not sending the response body at all in such cases, since not sending the response body at all is believed to be at least questionable, and might break various filters which do not expect such behaviour.
author Maxim Dounin <mdounin@mdounin.ru>
date Sat, 28 Jan 2023 05:23:33 +0300
parents 2af1287d2da7
children 0af598651e33
comparison
equal deleted inserted replaced
8123:1c3b78d7cdc9 8124:f5515e727656
1801 if (ngx_http_set_content_type(r) != NGX_OK) { 1801 if (ngx_http_set_content_type(r) != NGX_OK) {
1802 return NGX_HTTP_INTERNAL_SERVER_ERROR; 1802 return NGX_HTTP_INTERNAL_SERVER_ERROR;
1803 } 1803 }
1804 } 1804 }
1805 1805
1806 if (r != r->main && val.len == 0) {
1807 return ngx_http_send_header(r);
1808 }
1809
1810 b = ngx_calloc_buf(r->pool); 1806 b = ngx_calloc_buf(r->pool);
1811 if (b == NULL) { 1807 if (b == NULL) {
1812 return NGX_HTTP_INTERNAL_SERVER_ERROR; 1808 return NGX_HTTP_INTERNAL_SERVER_ERROR;
1813 } 1809 }
1814 1810
1815 b->pos = val.data; 1811 b->pos = val.data;
1816 b->last = val.data + val.len; 1812 b->last = val.data + val.len;
1817 b->memory = val.len ? 1 : 0; 1813 b->memory = val.len ? 1 : 0;
1818 b->last_buf = (r == r->main) ? 1 : 0; 1814 b->last_buf = (r == r->main) ? 1 : 0;
1819 b->last_in_chain = 1; 1815 b->last_in_chain = 1;
1816 b->sync = (b->last_buf || b->memory) ? 0 : 1;
1820 1817
1821 out.buf = b; 1818 out.buf = b;
1822 out.next = NULL; 1819 out.next = NULL;
1823 1820
1824 rc = ngx_http_send_header(r); 1821 rc = ngx_http_send_header(r);