@@ -60,13 +60,15 @@ module AP_MODULE_DECLARE_DATA redirectionio_module = {
60
60
};
61
61
62
62
static void redirectionio_register_hooks (apr_pool_t * p ) {
63
- ap_hook_type_checker (redirectionio_match_handler , NULL , NULL , APR_HOOK_LAST );
63
+ ap_hook_type_checker (redirectionio_match_handler , NULL , NULL , APR_HOOK_FIRST );
64
+ ap_hook_fixups (redirectionio_match_handler , NULL , NULL , APR_HOOK_FIRST );
64
65
65
66
ap_hook_handler (redirectionio_redirect_handler , NULL , NULL , APR_HOOK_FIRST );
66
67
ap_hook_log_transaction (redirectionio_log_handler , NULL , NULL , APR_HOOK_MIDDLE );
67
68
68
69
ap_hook_insert_filter (ap_headers_insert_output_filter , NULL , NULL , APR_HOOK_LAST );
69
70
ap_hook_insert_error_filter (ap_headers_insert_output_filter , NULL , NULL , APR_HOOK_LAST );
71
+
70
72
ap_register_output_filter ("redirectionio_redirect_filter" , redirectionio_filter_match_on_response , NULL , AP_FTYPE_CONTENT_SET );
71
73
ap_register_output_filter ("redirectionio_header_filter" , redirectionio_filter_header_filtering , NULL , AP_FTYPE_CONTENT_SET );
72
74
ap_register_output_filter ("redirectionio_body_filter" , redirectionio_filter_body_filtering , NULL , AP_FTYPE_CONTENT_SET );
@@ -117,7 +119,7 @@ static int redirectionio_match_handler(request_rec *r) {
117
119
118
120
redirectionio_release_connection (conn , config , r -> pool );
119
121
120
- return APR_SUCCESS ;
122
+ return DECLINED ;
121
123
}
122
124
123
125
static void ap_headers_insert_output_filter (request_rec * r ) {
@@ -132,17 +134,9 @@ static void ap_headers_insert_output_filter(request_rec *r) {
132
134
return ;
133
135
}
134
136
135
- if (ctx -> status != 0 && ctx -> match_on_response_status != 0 && !ctx -> is_redirected && r -> status == ctx -> match_on_response_status ) {
136
- ap_add_output_filter ("redirectionio_redirect_filter" , ctx , r , r -> connection );
137
- }
138
-
139
- if (ctx -> should_filter_headers == 1 ) {
140
- ap_add_output_filter ("redirectionio_header_filter" , ctx , r , r -> connection );
141
- }
142
-
143
- if (ctx -> should_filter_body == 1 ) {
144
- ap_add_output_filter ("redirectionio_body_filter" , ctx , r , r -> connection );
145
- }
137
+ ap_add_output_filter ("redirectionio_redirect_filter" , ctx , r , r -> connection );
138
+ ap_add_output_filter ("redirectionio_header_filter" , ctx , r , r -> connection );
139
+ ap_add_output_filter ("redirectionio_body_filter" , ctx , r , r -> connection );
146
140
}
147
141
148
142
static int redirectionio_redirect_handler (request_rec * r ) {
@@ -155,6 +149,10 @@ static int redirectionio_redirect_handler(request_rec *r) {
155
149
156
150
redirectionio_context * ctx = ap_get_module_config (r -> request_config , & redirectionio_module );
157
151
152
+ if (ctx == NULL ) {
153
+ return DECLINED ;
154
+ }
155
+
158
156
// No match here
159
157
if (ctx -> status == 0 || ctx -> is_redirected == 1 ) {
160
158
return DECLINED ;
@@ -177,6 +175,14 @@ static int redirectionio_redirect_handler(request_rec *r) {
177
175
static apr_status_t redirectionio_filter_match_on_response (ap_filter_t * f , apr_bucket_brigade * bb ) {
178
176
redirectionio_context * ctx = (redirectionio_context * )f -> ctx ;
179
177
178
+ if (ctx == NULL ) {
179
+ return ap_pass_brigade (f -> next , bb );
180
+ }
181
+
182
+ if (ctx -> is_redirected || ctx -> status == 0 || (ctx -> match_on_response_status > 0 && ctx -> match_on_response_status != f -> r -> status )) {
183
+ return ap_pass_brigade (f -> next , bb );
184
+ }
185
+
180
186
if (ctx -> status != 410 ) {
181
187
apr_table_setn (f -> r -> headers_out , "Location" , ctx -> target );
182
188
}
@@ -194,20 +200,28 @@ static apr_status_t redirectionio_filter_header_filtering(ap_filter_t *f, apr_bu
194
200
redirectionio_context * ctx = (redirectionio_context * )f -> ctx ;
195
201
redirectionio_config * config = (redirectionio_config * ) ap_get_module_config (f -> r -> per_dir_config , & redirectionio_module );
196
202
203
+ if (ctx == NULL ) {
204
+ return ap_pass_brigade (f -> next , bb );
205
+ }
206
+
207
+ if (ctx -> should_filter_headers == 0 || (ctx -> is_redirected != 1 && ctx -> match_on_response_status > 0 && ctx -> match_on_response_status != f -> r -> status )) {
208
+ return ap_pass_brigade (f -> next , bb );
209
+ }
210
+
197
211
ap_remove_output_filter (f );
198
212
199
213
// Get connection
200
214
redirectionio_connection * conn = redirectionio_acquire_connection (config , f -> r -> pool );
201
215
202
216
if (conn == NULL ) {
203
- return ap_pass_brigade (f -> next , bb );;
217
+ return ap_pass_brigade (f -> next , bb );
204
218
}
205
219
206
220
// Send headers
207
221
if (redirectionio_protocol_send_filter_headers (conn , ctx , f -> r , config -> project_key ) != APR_SUCCESS ) {
208
222
redirectionio_invalidate_connection (conn , config , f -> r -> pool );
209
223
210
- return ap_pass_brigade (f -> next , bb );;
224
+ return ap_pass_brigade (f -> next , bb );
211
225
}
212
226
213
227
redirectionio_release_connection (conn , config , f -> r -> pool );
@@ -224,6 +238,14 @@ static apr_status_t redirectionio_filter_body_filtering(ap_filter_t *f, apr_buck
224
238
int64_t input_size , output_size ;
225
239
apr_status_t rv ;
226
240
241
+ if (ctx == NULL ) {
242
+ return ap_pass_brigade (f -> next , bb );
243
+ }
244
+
245
+ if (ctx -> should_filter_body == 0 || (ctx -> is_redirected != 1 && ctx -> match_on_response_status > 0 && ctx -> match_on_response_status != f -> r -> status )) {
246
+ return ap_pass_brigade (f -> next , bb );
247
+ }
248
+
227
249
// If first -> remove content_length, get_connection, init filtering command
228
250
if (ctx -> body_filter_conn == NULL ) {
229
251
ctx -> body_filter_conn = redirectionio_acquire_connection (config , f -> r -> pool );
0 commit comments