@@ -1077,16 +1077,17 @@ ngx_http_modsecurity_header_filter(ngx_http_request_t *r) {
10771077const char * location ;
10781078ngx_table_elt_t * h ;
10791079ngx_int_t rc ;
1080-
1080+
10811081
10821082cf = ngx_http_get_module_loc_conf (r ,ngx_http_modsecurity );
10831083ctx = ngx_http_get_module_ctx (r ,ngx_http_modsecurity );
10841084
1085+ /* already processed, checking redirect action. */
10851086if (ctx && ctx -> complete
10861087&& r -> err_status >=NGX_HTTP_MOVED_PERMANENTLY
10871088&& r -> err_status < 308 ) {
10881089
1089- /* 3XX load redirect location header so that we can doredirec in phase 3,4 */
1090+ /* 3XX load redirect location header so that we can doredirect in phase 3,4 */
10901091location = apr_table_get (ctx -> req -> headers_out ,"Location" );
10911092
10921093if (location == NULL ) {
@@ -1113,7 +1114,8 @@ ngx_http_modsecurity_header_filter(ngx_http_request_t *r) {
11131114
11141115ngx_log_debug0 (NGX_LOG_DEBUG_HTTP ,r -> connection -> log ,0 ,"modSecurity: header filter" );
11151116
1116- if (r -> method == NGX_HTTP_HEAD || r -> header_only ) {
1117+ /* header only or SecResponseBodyAccess off */
1118+ if (r -> header_only || (!modsecIsResponseBodyAccessEnabled (ctx -> req )) ) {
11171119
11181120ctx -> complete = 1 ;
11191121
@@ -1126,17 +1128,18 @@ ngx_http_modsecurity_header_filter(ngx_http_request_t *r) {
11261128rc = ngx_http_modsecurity_status (r ,modsecProcessResponse (ctx -> req ));
11271129
11281130if (rc != NGX_DECLINED ) {
1129- return rc ;
1131+ return ngx_http_filter_finalize_request ( r , & ngx_http_modsecurity , rc ) ;
11301132 }
11311133
11321134if (ngx_http_modsecurity_save_headers_in (r )!= NGX_OK
11331135|| ngx_http_modsecurity_save_headers_out (r )!= NGX_OK ) {
1134- return NGX_HTTP_INTERNAL_SERVER_ERROR ;
1136+ return ngx_http_filter_finalize_request ( r , & ngx_http_modsecurity , NGX_HTTP_INTERNAL_SERVER_ERROR ) ;
11351137 }
11361138
11371139return ngx_http_next_header_filter (r );
11381140 }
11391141
1142+ /* SecResponseBodyAccess on, process rules in body filter */
11401143return NGX_OK ;
11411144}
11421145