Fixed: Nginx return 500 when request body is off

This commit is contained in:
Breno Silva 2013-03-05 02:38:46 -04:00
parent df383b9b80
commit 43162f52cf

View File

@ -372,7 +372,7 @@ ngx_http_modsecurity_handler(ngx_http_request_t *r)
return NGX_ERROR; return NGX_ERROR;
} }
ngx_http_set_ctx(r, ctx, ngx_http_modsecurity); ngx_http_set_ctx(r, ctx, ngx_http_modsecurity);
/* processing request headers */ /* processing request headers */
rc = modsecProcessRequestHeaders(ctx->req); rc = modsecProcessRequestHeaders(ctx->req);
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "ModSecurity: modsecProcessRequestHeaders %d", rc); ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "ModSecurity: modsecProcessRequestHeaders %d", rc);
@ -387,9 +387,11 @@ ngx_http_modsecurity_handler(ngx_http_request_t *r)
return NGX_DONE; return NGX_DONE;
} }
/* other method */ /* other method */
rc = modsecProcessRequestBody(ctx->req); if(modsecIsRequestBodyAccessEnabled(ctx->req)) {
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "ModSecurity: modsecProcessRequestBody %d", rc); rc = modsecProcessRequestBody(ctx->req);
} ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "ModSecurity: modsecProcessRequestBody %d", rc);
}
}
if (rc != DECLINED) { if (rc != DECLINED) {
@ -398,7 +400,7 @@ ngx_http_modsecurity_handler(ngx_http_request_t *r)
return NGX_HTTP_INTERNAL_SERVER_ERROR; return NGX_HTTP_INTERNAL_SERVER_ERROR;
} }
return rc; return rc;
} }
return NGX_DECLINED; return NGX_DECLINED;
} }
@ -430,13 +432,15 @@ ngx_http_modsecurity_body_handler(ngx_http_request_t *r)
return ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); return ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
} }
rc = DECLINED;
r->request_body = NULL; r->request_body = NULL;
modsecSetBodyBrigade(ctx->req, ctx->brigade); modsecSetBodyBrigade(ctx->req, ctx->brigade);
if(modsecIsRequestBodyAccessEnabled(ctx->req)) if(modsecIsRequestBodyAccessEnabled(ctx->req)) {
rc = modsecProcessRequestBody(ctx->req); rc = modsecProcessRequestBody(ctx->req);
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "ModSecurity: modsecProcessRequestBody %d", rc); ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "ModSecurity: modsecProcessRequestBody %d", rc);
}
if (rc != DECLINED) { if (rc != DECLINED) {
/* Nginx and Apache share same response code */ /* Nginx and Apache share same response code */