Welcome! Log In Create A New Profile

Advanced

[nginx] Limit req: limit_req_dry_run directive.

Roman Arutyunyan
June 05, 2019 01:34PM
details: https://hg.nginx.org/nginx/rev/2db68852d6a0
branches:
changeset: 7515:2db68852d6a0
user: Roman Arutyunyan <arut@nginx.com>
date: Wed Jun 05 19:55:27 2019 +0300
description:
Limit req: limit_req_dry_run directive.

A new directive limit_req_dry_run allows enabling the dry run mode. In this
mode requests are neither rejected nor delayed, but reject/delay status is
logged as usual.

diffstat:

src/http/modules/ngx_http_limit_req_module.c | 29 ++++++++++++++++++++++++---
1 files changed, 25 insertions(+), 4 deletions(-)

diffs (83 lines):

diff -r 319242d2ddc9 -r 2db68852d6a0 src/http/modules/ngx_http_limit_req_module.c
--- a/src/http/modules/ngx_http_limit_req_module.c Mon Jun 03 20:33:26 2019 +0300
+++ b/src/http/modules/ngx_http_limit_req_module.c Wed Jun 05 19:55:27 2019 +0300
@@ -53,6 +53,7 @@ typedef struct {
ngx_uint_t limit_log_level;
ngx_uint_t delay_log_level;
ngx_uint_t status_code;
+ ngx_flag_t dry_run;
} ngx_http_limit_req_conf_t;


@@ -118,6 +119,13 @@ static ngx_command_t ngx_http_limit_req
offsetof(ngx_http_limit_req_conf_t, status_code),
&ngx_http_limit_req_status_bounds },

+ { ngx_string("limit_req_dry_run"),
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
+ ngx_conf_set_flag_slot,
+ NGX_HTTP_LOC_CONF_OFFSET,
+ offsetof(ngx_http_limit_req_conf_t, dry_run),
+ NULL },
+
ngx_null_command
};

@@ -230,9 +238,10 @@ ngx_http_limit_req_handler(ngx_http_requ

if (rc == NGX_BUSY) {
ngx_log_error(lrcf->limit_log_level, r->connection->log, 0,
- "limiting requests, excess: %ui.%03ui by zone \"%V\"",
- excess / 1000, excess % 1000,
- &limit->shm_zone->shm.name);
+ "limiting requests%s, excess: %ui.%03ui by zone \"%V\"",
+ lrcf->dry_run ? ", dry run" : "",
+ excess / 1000, excess % 1000,
+ &limit->shm_zone->shm.name);
}

while (n--) {
@@ -251,6 +260,10 @@ ngx_http_limit_req_handler(ngx_http_requ
ctx->node = NULL;
}

+ if (lrcf->dry_run) {
+ return NGX_DECLINED;
+ }
+
return lrcf->status_code;
}

@@ -267,9 +280,14 @@ ngx_http_limit_req_handler(ngx_http_requ
}

ngx_log_error(lrcf->delay_log_level, r->connection->log, 0,
- "delaying request, excess: %ui.%03ui, by zone \"%V\"",
+ "delaying request%s, excess: %ui.%03ui, by zone \"%V\"",
+ lrcf->dry_run ? ", dry run" : "",
excess / 1000, excess % 1000, &limit->shm_zone->shm.name);

+ if (lrcf->dry_run) {
+ return NGX_DECLINED;
+ }
+
if (ngx_handle_read_event(r->connection->read, 0) != NGX_OK) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
@@ -711,6 +729,7 @@ ngx_http_limit_req_create_conf(ngx_conf_

conf->limit_log_level = NGX_CONF_UNSET_UINT;
conf->status_code = NGX_CONF_UNSET_UINT;
+ conf->dry_run = NGX_CONF_UNSET;

return conf;
}
@@ -735,6 +754,8 @@ ngx_http_limit_req_merge_conf(ngx_conf_t
ngx_conf_merge_uint_value(conf->status_code, prev->status_code,
NGX_HTTP_SERVICE_UNAVAILABLE);

+ ngx_conf_merge_value(conf->dry_run, prev->dry_run, 0);
+
return NGX_CONF_OK;
}

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[nginx] Limit req: limit_req_dry_run directive.

Roman Arutyunyan 222 June 05, 2019 01:34PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 60
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready