@@ -87,9 +87,8 @@ static ngx_int_t ngx_http_firetail_handler_internal(ngx_http_request_t *request)
87
87
88
88
// Update the ctx with the new updated body
89
89
ctx -> request_body = updated_request_body ;
90
- // run the validation
91
- FiretailMainConfig * main_config = ngx_http_get_module_main_conf (request , ngx_firetail_module );
92
90
91
+ // run the validation
93
92
void * validator_module = dlopen ("/etc/nginx/modules/firetail-validator.so" , RTLD_LAZY );
94
93
if (!validator_module ) {
95
94
return NGX_ERROR ;
@@ -103,23 +102,17 @@ static ngx_int_t ngx_http_firetail_handler_internal(ngx_http_request_t *request)
103
102
}
104
103
ngx_log_debug (NGX_LOG_DEBUG , request -> connection -> log , 0 , "Validating request body..." );
105
104
106
- char * schema = ngx_palloc (request -> pool , main_config -> FiretailAppSpec .len );
107
- ngx_memcpy (schema , main_config -> FiretailAppSpec .data , main_config -> FiretailAppSpec .len );
108
-
109
- struct ValidateRequestBody_return validation_result = request_body_validator (
110
- schema , strlen (schema ), ctx -> request_body , ctx -> request_body_size , request -> unparsed_uri .data ,
111
- request -> unparsed_uri .len , request -> method_name .data , request -> method_name .len , (char * )ctx -> request_headers_json ,
112
- ctx -> request_headers_json_size );
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 );
113
109
114
110
ngx_log_debug (NGX_LOG_DEBUG , request -> connection -> log , 0 , "Validation request result: %d" , validation_result .r0 );
115
111
ngx_log_debug (NGX_LOG_DEBUG , request -> connection -> log , 0 , "Validating request body: %s" , validation_result .r1 );
116
112
117
113
// if validation is unsuccessful, return bad request
118
114
if (validation_result .r0 > 0 ) return ngx_http_firetail_request (request , NULL , chain_head , validation_result .r1 );
119
115
120
- // else continue request
121
- ngx_pfree (request -> pool , schema );
122
-
123
116
dlclose (validator_module );
124
117
125
118
return NGX_OK ; // can be NGX_DECLINED - see ngx_http_mirror_handler_internal
@@ -201,34 +194,6 @@ static void *CreateFiretailMainConfig(ngx_conf_t *configuration_object) {
201
194
http_main_config -> FiretailApiToken = firetail_api_token ;
202
195
http_main_config -> FiretailUrl = firetail_url ;
203
196
204
- // load appspec schema
205
- // schema file pointer
206
- FILE * schema ;
207
-
208
- // initialize variables with an arbitary size
209
- char data [SIZE ];
210
- char str [SIZE ];
211
-
212
- // open schema spec
213
- schema = fopen ("/etc/nginx/appspec.yml" , "r" );
214
- if (schema == NULL ) {
215
- printf ("Error! count not load schema" );
216
- exit (1 );
217
- }
218
-
219
- // resize data
220
- while (fgets (str , SIZE , schema )) {
221
- // concatenate the string with line termination \0
222
- // at the end
223
- strcat (data , str );
224
- }
225
-
226
- ngx_str_t spec = ngx_string (data );
227
-
228
- http_main_config -> FiretailAppSpec = spec ;
229
-
230
- fclose (schema );
231
-
232
197
return http_main_config ;
233
198
}
234
199
0 commit comments