comparison src/http/modules/ngx_http_slice_filter_module.c @ 6963:3ff293cfdab8

Slice filter: prevented slice redirection (ticket #1219). When a slice subrequest was redirected to a new location, its context was lost. After its completion, a new slice subrequest for the same slice was created. This could lead to infinite loop. Now the slice module makes sure each slice subrequest starts output with the slice context available.
author Roman Arutyunyan <arut@nginx.com>
date Fri, 31 Mar 2017 21:47:56 +0300
parents a97ad1663ef4
children e3723f2a11b7
comparison
equal deleted inserted replaced
6962:a97ad1663ef4 6963:3ff293cfdab8
18 typedef struct { 18 typedef struct {
19 off_t start; 19 off_t start;
20 off_t end; 20 off_t end;
21 ngx_str_t range; 21 ngx_str_t range;
22 ngx_str_t etag; 22 ngx_str_t etag;
23 ngx_uint_t last; /* unsigned last:1; */ 23 unsigned last:1;
24 unsigned active:1;
24 ngx_http_request_t *sr; 25 ngx_http_request_t *sr;
25 } ngx_http_slice_ctx_t; 26 } ngx_http_slice_ctx_t;
26 27
27 28
28 typedef struct { 29 typedef struct {
168 cr.start, cr.end); 169 cr.start, cr.end);
169 return NGX_ERROR; 170 return NGX_ERROR;
170 } 171 }
171 172
172 ctx->start = end; 173 ctx->start = end;
174 ctx->active = 1;
173 175
174 r->headers_out.status = NGX_HTTP_OK; 176 r->headers_out.status = NGX_HTTP_OK;
175 r->headers_out.status_line.len = 0; 177 r->headers_out.status_line.len = 0;
176 r->headers_out.content_length_n = cr.complete_length; 178 r->headers_out.content_length_n = cr.complete_length;
177 r->headers_out.content_offset = cr.start; 179 r->headers_out.content_offset = cr.start;
236 238
237 if (ctx->sr && !ctx->sr->done) { 239 if (ctx->sr && !ctx->sr->done) {
238 return rc; 240 return rc;
239 } 241 }
240 242
243 if (!ctx->active) {
244 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
245 "missing slice response");
246 return NGX_ERROR;
247 }
248
241 if (ctx->start >= ctx->end) { 249 if (ctx->start >= ctx->end) {
242 ngx_http_set_ctx(r, NULL, ngx_http_slice_filter_module); 250 ngx_http_set_ctx(r, NULL, ngx_http_slice_filter_module);
243 ngx_http_send_special(r, NGX_HTTP_LAST); 251 ngx_http_send_special(r, NGX_HTTP_LAST);
244 return rc; 252 return rc;
245 } 253 }
260 slcf = ngx_http_get_module_loc_conf(r, ngx_http_slice_filter_module); 268 slcf = ngx_http_get_module_loc_conf(r, ngx_http_slice_filter_module);
261 269
262 ctx->range.len = ngx_sprintf(ctx->range.data, "bytes=%O-%O", ctx->start, 270 ctx->range.len = ngx_sprintf(ctx->range.data, "bytes=%O-%O", ctx->start,
263 ctx->start + (off_t) slcf->size - 1) 271 ctx->start + (off_t) slcf->size - 1)
264 - ctx->range.data; 272 - ctx->range.data;
273
274 ctx->active = 0;
265 275
266 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 276 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
267 "http slice subrequest: \"%V\"", &ctx->range); 277 "http slice subrequest: \"%V\"", &ctx->range);
268 278
269 return rc; 279 return rc;