@@ -88,6 +88,9 @@ static ngx_int_t ngx_http_firetail_handler_internal(ngx_http_request_t *request)
88
88
// Update the ctx with the new updated body
89
89
ctx -> request_body = updated_request_body ;
90
90
91
+ // Get the main config so we can check if we have 404s disabled from the middleware
92
+ FiretailMainConfig * main_config = ngx_http_get_module_main_conf (request , ngx_firetail_module );
93
+
91
94
// run the validation
92
95
void * validator_module = dlopen ("/etc/nginx/modules/firetail-validator.so" , RTLD_LAZY );
93
96
if (!validator_module ) {
@@ -102,10 +105,10 @@ static ngx_int_t ngx_http_firetail_handler_internal(ngx_http_request_t *request)
102
105
}
103
106
ngx_log_debug (NGX_LOG_DEBUG , request -> connection -> log , 0 , "Validating request body..." );
104
107
105
- struct ValidateRequestBody_return validation_result =
106
- request_body_validator ( ctx -> request_body , ctx -> request_body_size , request -> unparsed_uri . data ,
107
- request -> unparsed_uri .len , request -> method_name . data , request -> method_name .len ,
108
- (char * )ctx -> request_headers_json , ctx -> request_headers_json_size );
108
+ struct ValidateRequestBody_return validation_result = request_body_validator (
109
+ main_config -> FiretailAllowUndefinedRoutes . data , main_config -> FiretailAllowUndefinedRoutes . len , ctx -> request_body ,
110
+ ctx -> request_body_size , request -> unparsed_uri .data , request -> unparsed_uri . len , request -> method_name .data ,
111
+ request -> method_name . len , (char * )ctx -> request_headers_json , ctx -> request_headers_json_size );
109
112
110
113
ngx_log_debug (NGX_LOG_DEBUG , request -> connection -> log , 0 , "Validation request result: %d" , validation_result .r0 );
111
114
ngx_log_debug (NGX_LOG_DEBUG , request -> connection -> log , 0 , "Validating request body: %s" , validation_result .r1 );
@@ -210,8 +213,8 @@ ngx_http_module_t kFiretailModuleContext = {
210
213
NULL // merge location configuration
211
214
};
212
215
213
- char * EnableFiretailDirectiveInit (ngx_conf_t * configuration_object , ngx_command_t * command_definition ,
214
- void * http_main_config ) {
216
+ char * FiretailApiTokenDirectiveCallback (ngx_conf_t * configuration_object , ngx_command_t * command_definition ,
217
+ void * http_main_config ) {
215
218
// TODO: validate the args given to the directive
216
219
217
220
// Find the firetail_api_key_field given the config pointer & offset in cmd
@@ -225,8 +228,8 @@ char *EnableFiretailDirectiveInit(ngx_conf_t *configuration_object, ngx_command_
225
228
return NGX_CONF_OK ;
226
229
}
227
230
228
- char * EnableFiretailUrlInit (ngx_conf_t * configuration_object , ngx_command_t * command_definition ,
229
- void * http_main_config ) {
231
+ char * FiretailUrlDirectiveCallback (ngx_conf_t * configuration_object , ngx_command_t * command_definition ,
232
+ void * http_main_config ) {
230
233
// TODO: validate the args given to the directive
231
234
232
235
// Find the firetail_api_key_field given the config pointer & offset in cmd
@@ -240,16 +243,43 @@ char *EnableFiretailUrlInit(ngx_conf_t *configuration_object, ngx_command_t *com
240
243
return NGX_CONF_OK ;
241
244
}
242
245
243
- ngx_command_t kFiretailCommands [3 ] = {
246
+ char * FiretailAllowUndefinedRoutesDirectiveCallback (ngx_conf_t * configuration_object , ngx_command_t * command_definition ,
247
+ void * http_main_config ) {
248
+ // Find the firetail_api_key_field given the config pointer & offset in cmd
249
+ char * firetail_config = http_main_config ;
250
+ ngx_str_t * firetail_allow_undefined_routes_field = (ngx_str_t * )(firetail_config + command_definition -> offset );
251
+
252
+ // Get the string value from the configuraion object
253
+ ngx_str_t * value = configuration_object -> args -> elts ;
254
+ * firetail_allow_undefined_routes_field = value [1 ];
255
+
256
+ return NGX_CONF_OK ;
257
+ }
258
+
259
+ ngx_command_t kFiretailCommands [4 ] = {
244
260
{// Name of the directive
245
261
ngx_string ("firetail_api_token" ),
246
262
// Valid in the main config and takes one arg
247
263
NGX_HTTP_MAIN_CONF | NGX_CONF_TAKE1 ,
248
264
// A callback function to be called when the directive is found in the
249
265
// configuration
250
- EnableFiretailDirectiveInit , NGX_HTTP_MAIN_CONF_OFFSET , offsetof(FiretailMainConfig , FiretailApiToken ), NULL },
251
- {ngx_string ("firetail_url" ), NGX_HTTP_MAIN_CONF | NGX_CONF_TAKE1 , EnableFiretailUrlInit , NGX_HTTP_MAIN_CONF_OFFSET ,
252
- offsetof(FiretailMainConfig , FiretailUrl ), NULL },
266
+ FiretailApiTokenDirectiveCallback , NGX_HTTP_MAIN_CONF_OFFSET , offsetof(FiretailMainConfig , FiretailApiToken ),
267
+ NULL },
268
+ {// Name of the directive
269
+ ngx_string ("firetail_url" ),
270
+ // Valid in the main config and takes one arg
271
+ NGX_HTTP_MAIN_CONF | NGX_CONF_TAKE1 ,
272
+ // A callback function to be called when the directive is found in the
273
+ // configuration
274
+ FiretailUrlDirectiveCallback , NGX_HTTP_MAIN_CONF_OFFSET , offsetof(FiretailMainConfig , FiretailUrl ), NULL },
275
+ {// Name of the directive
276
+ ngx_string ("firetail_allow_undefined_routes" ),
277
+ // Valid in the main config and takes one arg
278
+ NGX_HTTP_MAIN_CONF | NGX_CONF_TAKE1 ,
279
+ // A callback function to be called when the directive is found in the
280
+ // configuration
281
+ FiretailAllowUndefinedRoutesDirectiveCallback , NGX_HTTP_MAIN_CONF_OFFSET ,
282
+ offsetof(FiretailMainConfig , FiretailAllowUndefinedRoutes ), NULL },
253
283
ngx_null_command };
254
284
255
285
ngx_module_t ngx_firetail_module = {NGX_MODULE_V1 ,
0 commit comments