mirror of
https://github.com/nginx/nginx.git
synced 2024-12-26 00:41:02 -06:00
fix range in $r->sendfile
This commit is contained in:
parent
c49d3ec7d4
commit
0e8fc7a6b4
@ -336,6 +336,11 @@ ngx_http_range_header_filter(ngx_http_request_t *r)
|
||||
|
||||
r->headers_out.content_length_n = range->end - range->start;
|
||||
|
||||
if (r->headers_out.content_length) {
|
||||
r->headers_out.content_length->hash = 0;
|
||||
r->headers_out.content_length = NULL;
|
||||
}
|
||||
|
||||
return ngx_http_next_header_filter(r);
|
||||
}
|
||||
|
||||
@ -441,36 +446,61 @@ ngx_http_range_header_filter(ngx_http_request_t *r)
|
||||
}
|
||||
|
||||
r->headers_out.content_length_n = len;
|
||||
|
||||
if (r->headers_out.content_length) {
|
||||
r->headers_out.content_length->hash = 0;
|
||||
r->headers_out.content_length = NULL;
|
||||
}
|
||||
|
||||
return ngx_http_next_header_filter(r);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* TODO:
|
||||
* buffer or buffers is in memory
|
||||
* range or ranges are overlapped in buffers
|
||||
*/
|
||||
|
||||
static ngx_int_t
|
||||
ngx_http_range_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
|
||||
{
|
||||
ngx_uint_t i;
|
||||
ngx_buf_t *b;
|
||||
ngx_buf_t *b, *buf;
|
||||
ngx_chain_t *out, *hcl, *rcl, *dcl, **ll;
|
||||
ngx_http_range_t *range;
|
||||
ngx_http_range_filter_ctx_t *ctx;
|
||||
|
||||
if (r->headers_out.ranges.nelts == 0) {
|
||||
if (in == NULL || r->headers_out.ranges.nelts == 0) {
|
||||
return ngx_http_next_body_filter(r, in);
|
||||
}
|
||||
|
||||
range = r->headers_out.ranges.elts;
|
||||
buf = in->buf;
|
||||
|
||||
if (!buf->in_file) {
|
||||
goto in_memory;
|
||||
}
|
||||
|
||||
if (!buf->last_buf) {
|
||||
for (i = 0; i < r->headers_out.ranges.nelts; i++) {
|
||||
if (buf->file_pos > range[i].start
|
||||
|| buf->file_last < range[i].end)
|
||||
{
|
||||
goto overlapped;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* the optimized version for the static files only
|
||||
* that are passed in the single file buf
|
||||
* that are passed in the single file buffer
|
||||
*/
|
||||
|
||||
if (in && in->buf->in_file && in->buf->last_buf) {
|
||||
range = r->headers_out.ranges.elts;
|
||||
|
||||
if (r->headers_out.ranges.nelts == 1) {
|
||||
in->buf->file_pos = range->start;
|
||||
in->buf->file_last = range->end;
|
||||
|
||||
buf->file_pos = range->start;
|
||||
buf->file_last = range->end;
|
||||
|
||||
return ngx_http_next_body_filter(r, in);
|
||||
}
|
||||
@ -534,7 +564,7 @@ ngx_http_range_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
|
||||
b->in_file = 1;
|
||||
b->file_pos = range[i].start;
|
||||
b->file_last = range[i].end;
|
||||
b->file = in->buf->file;
|
||||
b->file = buf->file;
|
||||
|
||||
dcl = ngx_alloc_chain_link(r->pool);
|
||||
if (dcl == NULL) {
|
||||
@ -580,11 +610,15 @@ ngx_http_range_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
|
||||
*ll = hcl;
|
||||
|
||||
return ngx_http_next_body_filter(r, out);
|
||||
}
|
||||
|
||||
/* TODO: alert */
|
||||
in_memory:
|
||||
|
||||
return ngx_http_next_body_filter(r, in);
|
||||
overlapped:
|
||||
|
||||
ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
|
||||
"range in memory buffer or in overlapped buffers");
|
||||
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user