@@ -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 ;
@@ -1170,25 +1148,19 @@ ngx_http_modsecurity_handler(ngx_http_request_t *r) {
11701148 ngx_log_debug0 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
11711149 "ModSec: ModSecurity is not enabled or not a main request." );
11721150
1173- ctx = ngx_http_modsecurity_create_ctx (r );
1174-
11751151 return NGX_DECLINED ;
1176- if (ngx_http_set_pool_ctx (r , ctx , ngx_http_modsecurity ) != NGX_OK ) {
1177- return NGX_ERROR ;
11781152 }
11791153
11801154 ctx = ngx_http_get_module_ctx (r , ngx_http_modsecurity );
11811155
11821156 ngx_log_debug1 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
11831157 "ModSec: Recovering ctx: %p" , ctx );
1184- ngx_log_debug0 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
1185- "ModSec: ctx is null, nothing we can do, returning." );
11861158
11871159 if (ctx == NULL ) {
11881160 ctx = ngx_http_modsecurity_create_ctx (r );
11891161
11901162 ngx_http_set_ctx (r , ctx , ngx_http_modsecurity );
1191- "ModSec: ctx is now: %p / count: %d" , ctx , r -> main -> count );
1163+
11921164 if (ngx_http_set_pool_ctx (r , ctx , ngx_http_modsecurity ) != NGX_OK ) {
11931165 return NGX_ERROR ;
11941166 }
@@ -1206,17 +1178,19 @@ ngx_http_modsecurity_handler(ngx_http_request_t *r) {
12061178 ngx_log_debug2 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
12071179 "ModSec: ctx is now: %p / count: %d" , ctx , r -> main -> count );
12081180
1181+ if (modsecContextState (ctx -> req ) == MODSEC_DISABLED ) {
12091182 ngx_log_debug1 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
12101183 "ModSec: ModSecurity was disabled, returning...." , ctx );
12111184
1185+ return NGX_DECLINED ;
1186+ }
12121187 if (ctx -> waiting_more_body == 1 ) {
12131188 ngx_log_debug1 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
12141189 "ModSec: waiting for more data before proceed. / count: %d" ,
12151190 r -> main -> count );
12161191
12171192 return NGX_DONE ;
12181193 }
1219- ngx_http_modsecurity_request_read );
12201194
12211195 if (ctx -> body_requested == 0 ) {
12221196 ngx_log_debug (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
@@ -1258,23 +1232,6 @@ ngx_http_modsecurity_handler(ngx_http_request_t *r) {
12581232
12591233 }
12601234
1261- ngx_log_debug0 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
1262- "ModSec: request is ready to be processed." );
1263- rc = ngx_http_modsecurity_process_request (r );
1264- ctx -> request_processed = 1 ;
1265- if (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE ) {
1266- ngx_log_debug1 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
1267- "ModSec: returning a special response after process " \
1268- "a request: %d" , rc );
1269-
1270- return rc ;
1271- }
1272-
1273- void
1274- ngx_http_modsecurity_request_read (ngx_http_request_t * r )
1275- {
1276-
1277-
12781235 ngx_log_debug0 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
12791236 "ModSec: returning NGX_DECLINED." );
12801237
@@ -1475,7 +1432,7 @@ ngx_http_modsecurity_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
14751432 }
14761433
14771434 return ngx_http_next_body_filter (r , out );
1478- #endif
1435+
14791436 return NGX_OK ;
14801437}
14811438#endif
0 commit comments