comparison ngx_http_compose_filter_module.c @ 2:ed63d0bd4d14

Correctly handle complex body filtering. - Postpone filter will maintain subrequests order, so don't worry about it. - Wait for last buffer before running subrequests, and don't touch anything after it. This allows us to reliably suppress whole original response.
author Maxim Dounin <mdounin@mdounin.ru>
date Tue, 15 Jul 2008 06:12:40 +0400
parents ba5471a3c988
children 37c6f2e0f278
comparison
equal deleted inserted replaced
1:ba5471a3c988 2:ed63d0bd4d14
218 static ngx_int_t 218 static ngx_int_t
219 ngx_http_compose_body_filter(ngx_http_request_t *r, ngx_chain_t *in) 219 ngx_http_compose_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
220 { 220 {
221 ngx_str_t *uri, args; 221 ngx_str_t *uri, args;
222 ngx_int_t rc; 222 ngx_int_t rc;
223 ngx_uint_t i, flags; 223 ngx_uint_t i, flags, last;
224 ngx_http_request_t *sr; 224 ngx_http_request_t *sr;
225 ngx_http_compose_ctx_t *ctx; 225 ngx_http_compose_ctx_t *ctx;
226 226
227 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 227 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
228 "compose body filter"); 228 "compose body filter");
236 } 236 }
237 237
238 if (ctx->done) { 238 if (ctx->done) {
239 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 239 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
240 "compose body filter: done"); 240 "compose body filter: done");
241 /* XXX wrong: should skip data instead */
242 return ngx_http_next_body_filter(r, in); 241 return ngx_http_next_body_filter(r, in);
243 } 242 }
244
245 ctx->done = 1;
246 243
247 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 244 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
248 "compose body filter, doing work"); 245 "compose body filter, doing work");
249 246
250 /* 247 /*
251 * Ignore body that comes to us, replace it with subrequests. 248 * Ignore body that comes to us, replace it with subrequests.
252 */ 249 */
253 250
251 last = 0;
252
253 for ( ; in; in = in->next) {
254 in->buf->pos = in->buf->last;
255 if (in->buf->last_buf) {
256 last = 1;
257 in->buf->last_buf = 0;
258 }
259 }
260
261 if (!last) {
262 return NGX_OK;
263 }
264
265 ctx->done = 1;
266
254 uri = ctx->parts.elts; 267 uri = ctx->parts.elts;
255 268
256 for (i = 0; i < ctx->parts.nelts; i++) { 269 for (i = 0; i < ctx->parts.nelts; i++) {
257 270
258 args.len = 0; 271 args.len = 0;
268 if (rc == NGX_ERROR || rc == NGX_DONE) { 281 if (rc == NGX_ERROR || rc == NGX_DONE) {
269 return rc; 282 return rc;
270 } 283 }
271 } 284 }
272 285
273 for ( ; in; in = in->next) {
274 in->buf->pos = in->buf->last;
275 in->buf->last_buf = 0;
276 }
277
278 /*
279 * XXX: what to do if non-static data? probably we should use post
280 * subrequest hook instead
281 */
282
283 return ngx_http_send_special(r, NGX_HTTP_LAST); 286 return ngx_http_send_special(r, NGX_HTTP_LAST);
284 } 287 }
285 288
286 289
287 static void * 290 static void *