comparison src/http/modules/ngx_http_static_module.c @ 9021: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 1c3b78d7cdc9
children
comparison
equal deleted inserted replaced
9020:1c3b78d7cdc9 9021:f5515e727656
236 236
237 if (ngx_http_set_content_type(r) != NGX_OK) { 237 if (ngx_http_set_content_type(r) != NGX_OK) {
238 return NGX_HTTP_INTERNAL_SERVER_ERROR; 238 return NGX_HTTP_INTERNAL_SERVER_ERROR;
239 } 239 }
240 240
241 if (r != r->main && of.size == 0) {
242 return ngx_http_send_header(r);
243 }
244
245 r->allow_ranges = 1; 241 r->allow_ranges = 1;
246 242
247 /* we need to allocate all before the header would be sent */ 243 /* we need to allocate all before the header would be sent */
248 244
249 b = ngx_calloc_buf(r->pool); 245 b = ngx_calloc_buf(r->pool);
266 b->file_last = of.size; 262 b->file_last = of.size;
267 263
268 b->in_file = b->file_last ? 1 : 0; 264 b->in_file = b->file_last ? 1 : 0;
269 b->last_buf = (r == r->main) ? 1 : 0; 265 b->last_buf = (r == r->main) ? 1 : 0;
270 b->last_in_chain = 1; 266 b->last_in_chain = 1;
267 b->sync = (b->last_buf || b->in_file) ? 0 : 1;
271 268
272 b->file->fd = of.fd; 269 b->file->fd = of.fd;
273 b->file->name = path; 270 b->file->name = path;
274 b->file->log = log; 271 b->file->log = log;
275 b->file->directio = of.is_directio; 272 b->file->directio = of.is_directio;