@@ -11,7 +11,7 @@ static int redirectionio_match_handler(request_rec *r);
1111static int redirectionio_redirect_handler (request_rec * r );
1212static int redirectionio_log_handler (request_rec * r );
1313
14- static int redirectionio_redirect_handler_for_status_code (request_rec * r , uint16_t status_code );
14+ static int redirectionio_redirect_handler_for_status_code (request_rec * r );
1515
1616static apr_status_t redirectionio_filter_match_on_response (ap_filter_t * f , apr_bucket_brigade * b );
1717static apr_status_t redirectionio_filter_header_filtering (ap_filter_t * f , apr_bucket_brigade * b );
@@ -131,6 +131,7 @@ static int redirectionio_match_handler(request_rec *r) {
131131 ctx -> action = NULL ;
132132 ctx -> response_headers = NULL ;
133133 ctx -> body_filter = NULL ;
134+ ctx -> backend_response_status_code = 0 ;
134135
135136 ap_set_module_config (r -> request_config , & redirectionio_module , ctx );
136137 redirectionio_connection * conn = redirectionio_acquire_connection (config , r -> pool );
@@ -171,7 +172,7 @@ static void ap_headers_insert_output_filter(request_rec *r) {
171172 ap_add_output_filter ("REDIRECTIONIO_BODY_FILTER" , ctx , r , r -> connection );
172173}
173174
174- static int redirectionio_redirect_handler_for_status_code (request_rec * r , uint16_t status_code ) {
175+ static int redirectionio_redirect_handler_for_status_code (request_rec * r ) {
175176 apr_uint16_t new_status_code ;
176177 redirectionio_config * config = (redirectionio_config * ) ap_get_module_config (r -> per_dir_config , & redirectionio_module );
177178
@@ -191,7 +192,7 @@ static int redirectionio_redirect_handler_for_status_code(request_rec *r, uint16
191192 return DECLINED ;
192193 }
193194
194- new_status_code = redirectionio_action_get_status_code (ctx -> action , status_code );
195+ new_status_code = redirectionio_action_get_status_code (ctx -> action , ctx -> backend_response_status_code );
195196
196197 if (new_status_code == 0 ) {
197198 return DECLINED ;
@@ -208,11 +209,26 @@ static int redirectionio_redirect_handler_for_status_code(request_rec *r, uint16
208209}
209210
210211static int redirectionio_redirect_handler (request_rec * r ) {
211- return redirectionio_redirect_handler_for_status_code (r , 0 );
212+ redirectionio_context * ctx = ap_get_module_config (r -> request_config , & redirectionio_module );
213+
214+ if (ctx == NULL ) {
215+ return DECLINED ;
216+ }
217+
218+ ctx -> backend_response_status_code = 0 ;
219+
220+ return redirectionio_redirect_handler_for_status_code (r );
212221}
213222
214223static apr_status_t redirectionio_filter_match_on_response (ap_filter_t * f , apr_bucket_brigade * bb ) {
215- redirectionio_redirect_handler_for_status_code (f -> r , f -> r -> status );
224+ redirectionio_context * ctx = ap_get_module_config (r -> request_config , & redirectionio_module );
225+
226+ if (ctx == NULL ) {
227+ return DECLINED ;
228+ }
229+
230+ ctx -> backend_response_status_code = f -> r -> status ;
231+ redirectionio_redirect_handler_for_status_code (f -> r );
216232
217233 /* remove ourselves from the filter chain */
218234 ap_remove_output_filter (f );
@@ -254,7 +270,7 @@ static apr_status_t redirectionio_filter_body_filtering(ap_filter_t *f, apr_buck
254270 }
255271
256272 if (ctx -> body_filter == NULL ) {
257- ctx -> body_filter = (struct REDIRECTIONIO_FilterBodyAction * )redirectionio_action_body_filter_create (ctx -> action , f -> r -> status );
273+ ctx -> body_filter = (struct REDIRECTIONIO_FilterBodyAction * )redirectionio_action_body_filter_create (ctx -> action , ctx -> backend_response_status_code );
258274
259275 if (ctx -> body_filter == NULL ) {
260276 ap_remove_output_filter (f );
@@ -373,7 +389,7 @@ static int redirectionio_log_handler(request_rec *r) {
373389 response = response -> next ;
374390 }
375391
376- should_log = redirectionio_action_should_log_request (context -> action , config -> enable_logs == 1 , response -> status );
392+ should_log = redirectionio_action_should_log_request (context -> action , config -> enable_logs == 1 , context -> backend_response_status_code );
377393
378394 if (!should_log ) {
379395 return DECLINED ;
0 commit comments