@@ -252,6 +252,15 @@ static apr_status_t redirectionio_filter_header_filtering(ap_filter_t *f, apr_bu
252
252
redirectionio_protocol_send_filter_headers (ctx , f -> r );
253
253
ap_remove_output_filter (f );
254
254
255
+ if (ctx -> body_filter == NULL ) {
256
+ ctx -> body_filter = (struct REDIRECTIONIO_FilterBodyAction * )redirectionio_action_body_filter_create (ctx -> action , ctx -> backend_response_status_code , ctx -> response_headers );
257
+
258
+ // Force chunked encoding
259
+ if (ctx -> body_filter != NULL ) {
260
+ apr_table_unset (f -> r -> headers_out , "Content-Length" );
261
+ }
262
+ }
263
+
255
264
return ap_pass_brigade (f -> next , bb );
256
265
}
257
266
@@ -267,21 +276,10 @@ static apr_status_t redirectionio_filter_body_filtering(ap_filter_t *f, apr_buck
267
276
return ap_pass_brigade (f -> next , bb );
268
277
}
269
278
270
- if (ctx -> action == NULL ) {
271
- return ap_pass_brigade (f -> next , bb );
272
- }
273
-
274
279
if (ctx -> body_filter == NULL ) {
275
- ctx -> body_filter = ( struct REDIRECTIONIO_FilterBodyAction * ) redirectionio_action_body_filter_create ( ctx -> action , ctx -> backend_response_status_code , ctx -> response_headers );
280
+ ap_remove_output_filter ( f );
276
281
277
- if (ctx -> body_filter == NULL ) {
278
- ap_remove_output_filter (f );
279
-
280
- return ap_pass_brigade (f -> next , bb );
281
- }
282
-
283
- // Force chunked encoding
284
- apr_table_unset (f -> r -> headers_out , "Content-Length" );
282
+ return ap_pass_brigade (f -> next , bb );
285
283
}
286
284
287
285
if (APR_BRIGADE_EMPTY (bb )) {
@@ -316,7 +314,10 @@ static apr_status_t redirectionio_filter_body_filtering(ap_filter_t *f, apr_buck
316
314
b_new = apr_bucket_transient_create ((const char * )output .data , output .len , f -> r -> connection -> bucket_alloc );
317
315
318
316
if (b_new == NULL ) {
317
+ redirectionio_action_body_filter_drop (ctx -> body_filter );
318
+ ctx -> body_filter = NULL ;
319
319
ap_remove_output_filter (f );
320
+ free (output .data );
320
321
321
322
return ap_pass_brigade (f -> next , bb );
322
323
}
@@ -328,13 +329,15 @@ static apr_status_t redirectionio_filter_body_filtering(ap_filter_t *f, apr_buck
328
329
329
330
if (APR_BUCKET_IS_EOS (b )) {
330
331
output = redirectionio_action_body_filter_close (ctx -> body_filter );
332
+ ctx -> body_filter = NULL ;
333
+ ap_remove_output_filter (f );
331
334
332
335
if (output .len > 0 ) {
333
336
// Create a new one
334
337
b_new = apr_bucket_transient_create ((const char * )output .data , output .len , f -> r -> connection -> bucket_alloc );
335
338
336
339
if (b_new == NULL ) {
337
- ap_remove_output_filter ( f );
340
+ free ( output . data );
338
341
339
342
return ap_pass_brigade (f -> next , bb );
340
343
}
@@ -347,16 +350,11 @@ static apr_status_t redirectionio_filter_body_filtering(ap_filter_t *f, apr_buck
347
350
b_new = apr_bucket_eos_create (f -> r -> connection -> bucket_alloc );
348
351
349
352
if (b_new == NULL ) {
350
- ap_remove_output_filter (f );
351
-
352
353
return ap_pass_brigade (f -> next , bb );
353
354
}
354
355
355
356
APR_BRIGADE_INSERT_TAIL (bb_new , b_new );
356
357
357
- // Remove filter
358
- ap_remove_output_filter (f );
359
-
360
358
// Break
361
359
break ;
362
360
}
0 commit comments