@@ -228,6 +228,7 @@ ngx_pstrdup0(ngx_pool_t *pool, ngx_str_t *src)
228228 return dst ;
229229}
230230
231+
231232/*
232233 * MultiplyDeBruijnBitPosition
233234 * http://graphics.stanford.edu/~seander/bithacks.html#ZerosOnRightMultLookup
@@ -565,9 +566,6 @@ ngx_http_modsecurity_load_request_body(ngx_http_request_t *r)
565566 ngx_http_modsecurity_ctx_t * ctx ;
566567 ngx_chain_t * chain ;
567568
568- ngx_log_debug (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
569- "ModSec: loading request body." );
570-
571569 ngx_log_debug (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
572570 "ModSec: loading request body." );
573571
@@ -601,12 +599,9 @@ ngx_http_modsecurity_load_request_body(ngx_http_request_t *r)
601599 }
602600#endif
603601
604- return NGX_ERROR ;
605- }
606- #endif
607-
608602 return NGX_OK ;
609603}
604+
610605static ngx_inline ngx_int_t
611606ngx_http_modsecurity_save_request_body (ngx_http_request_t * r )
612607{
@@ -627,23 +622,6 @@ ngx_http_modsecurity_save_request_body(ngx_http_request_t *r)
627622 apr_brigade_cleanup (ctx -> brigade );
628623 buf -> last += content_length ;
629624 r -> header_in = buf ;
630- if (r -> headers_in .content_length ) {
631- ngx_str_t * str = NULL ;
632- str = & r -> headers_in .content_length -> value ;
633- str -> data = ngx_palloc (r -> pool , NGX_OFF_T_LEN );
634- if (str -> data == NULL ) {
635- ngx_http_finalize_request (r , NGX_HTTP_INTERNAL_SERVER_ERROR );
636- return NGX_OK ;
637- }
638- str -> len = ngx_snprintf (str -> data , NGX_OFF_T_LEN , "%O" ,
639- content_length ) - str -> data ;
640- r -> headers_in .content_length_n = content_length ;
641- ngx_log_debug (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
642- "ModSec: Content length: %O, Content length n: %O" , content_length ,
643- r -> headers_in .content_length_n );
644- #else
645- apr_brigade_cleanup (ctx -> brigade );
646- #endif
647625
648626 if (r -> headers_in .content_length ) {
649627 ngx_str_t * str = NULL ;
@@ -1176,25 +1154,19 @@ ngx_http_modsecurity_handler(ngx_http_request_t *r) {
11761154 ngx_log_debug0 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
11771155 "ModSec: ModSecurity is not enabled or not a main request." );
11781156
1179- ctx = ngx_http_modsecurity_create_ctx (r );
1180-
11811157 return NGX_DECLINED ;
1182- if (ngx_http_set_pool_ctx (r , ctx , ngx_http_modsecurity ) != NGX_OK ) {
1183- return NGX_ERROR ;
11841158 }
11851159
11861160 ctx = ngx_http_get_module_ctx (r , ngx_http_modsecurity );
11871161
11881162 ngx_log_debug1 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
11891163 "ModSec: Recovering ctx: %p" , ctx );
1190- ngx_log_debug0 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
1191- "ModSec: ctx is null, nothing we can do, returning." );
11921164
11931165 if (ctx == NULL ) {
11941166 ctx = ngx_http_modsecurity_create_ctx (r );
11951167
11961168 ngx_http_set_ctx (r , ctx , ngx_http_modsecurity );
1197- "ModSec: ctx is now: %p / count: %d" , ctx , r -> main -> count );
1169+
11981170 if (ngx_http_set_pool_ctx (r , ctx , ngx_http_modsecurity ) != NGX_OK ) {
11991171 return NGX_ERROR ;
12001172 }
@@ -1212,17 +1184,19 @@ ngx_http_modsecurity_handler(ngx_http_request_t *r) {
12121184 ngx_log_debug2 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
12131185 "ModSec: ctx is now: %p / count: %d" , ctx , r -> main -> count );
12141186
1187+ if (modsecContextState (ctx -> req ) == MODSEC_DISABLED ) {
12151188 ngx_log_debug1 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
12161189 "ModSec: ModSecurity was disabled, returning...." , ctx );
12171190
1191+ return NGX_DECLINED ;
1192+ }
12181193 if (ctx -> waiting_more_body == 1 ) {
12191194 ngx_log_debug1 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
12201195 "ModSec: waiting for more data before proceed. / count: %d" ,
12211196 r -> main -> count );
12221197
12231198 return NGX_DONE ;
12241199 }
1225- ngx_http_modsecurity_request_read );
12261200
12271201 if (ctx -> body_requested == 0 ) {
12281202 ngx_log_debug (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
@@ -1264,23 +1238,6 @@ ngx_http_modsecurity_handler(ngx_http_request_t *r) {
12641238
12651239 }
12661240
1267- ngx_log_debug0 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
1268- "ModSec: request is ready to be processed." );
1269- rc = ngx_http_modsecurity_process_request (r );
1270- ctx -> request_processed = 1 ;
1271- if (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE ) {
1272- ngx_log_debug1 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
1273- "ModSec: returning a special response after process " \
1274- "a request: %d" , rc );
1275-
1276- return rc ;
1277- }
1278-
1279- void
1280- ngx_http_modsecurity_request_read (ngx_http_request_t * r )
1281- {
1282-
1283-
12841241 ngx_log_debug0 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
12851242 "ModSec: returning NGX_DECLINED." );
12861243
@@ -1481,7 +1438,7 @@ ngx_http_modsecurity_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
14811438 }
14821439
14831440 return ngx_http_next_body_filter (r , out );
1484- #endif
1441+
14851442 return NGX_OK ;
14861443}
14871444#endif
0 commit comments