Skip to content

Commit 344ec7d

Browse files
committed
Added cleanup handler for finalize request
1 parent 5f97bec commit 344ec7d

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

nginx/modsecurity/ngx_http_modsecurity.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ static ngx_int_t ngx_http_modsecurity_pass_to_backend(ngx_http_request_t *r);
7575

7676
static int ngx_http_modsecurity_drop_action(request_rec *r);
7777

78+
static void ngx_http_modsecurity_cleanup(void *data);
79+
7880
/* command handled by the module */
7981
static ngx_command_t ngx_http_modsecurity_commands[] = {
8082
{ ngx_string("ModSecurityConfig"),
@@ -451,6 +453,7 @@ ngx_http_modsecurity_handler(ngx_http_request_t *r)
451453
ngx_uint_t i;
452454
ngx_int_t rc;
453455
void **loc_conf;
456+
ngx_pool_cleanup_t *cln;
454457

455458
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "modSecurity: handler");
456459

@@ -538,6 +541,14 @@ ngx_http_modsecurity_handler(ngx_http_request_t *r)
538541
apr_table_setn(ctx->req->subprocess_env, "UNIQUE_ID", "12345");
539542
/* actually, we need ctx only for POST request body handling - don't like this part */
540543
apr_table_setn(ctx->req->notes, NOTE_NGINX_REQUEST_CTX, (const char *) ctx);
544+
545+
/* add cleanup */
546+
cln = ngx_pool_cleanup_add(r->pool, 0);
547+
if (cln == NULL) {
548+
return NGX_ERROR;
549+
}
550+
cln->data = ctx;
551+
cln->handler = ngx_http_modsecurity_cleanup;
541552
}
542553

543554
// r->keepalive = 0;
@@ -600,6 +611,16 @@ ngx_http_modsecurity_handler(ngx_http_request_t *r)
600611
return rc;
601612
}
602613

614+
static void
615+
ngx_http_modsecurity_cleanup(void *data)
616+
{
617+
ngx_http_modsecurity_ctx_t *ctx = data;
618+
619+
if (ctx->req != NULL) {
620+
(void) modsecFinishRequest(ctx->req);
621+
}
622+
}
623+
603624

604625
static void
605626
ngx_http_modsecurity_request_body_handler(ngx_http_request_t *r)

0 commit comments

Comments
 (0)