[PATCH] Limit req: Added "off" parameter to the 'limit_req' directive
Pavel V. Rochnyack
pavel2000 at ngs.ru
Tue Feb 9 18:09:33 UTC 2016
# HG changeset patch
# User Pavel V. Rochnyack <pavel2000 at ngs.ru>
# Date 1454835814 -21600
# Node ID 42a41d68c88ff25514cb501de657e8e8d54b5099
# Parent 3577c021f21eb4de6d09c1d624ba77ee9ee1eb6d
Limit req: Added "off" parameter to the 'limit_req' directive.
Added support for inherited "limit_req" directives disable.
diff -r 3577c021f21e -r 42a41d68c88f src/http/modules/ngx_http_limit_req_module.c
--- a/src/http/modules/ngx_http_limit_req_module.c Fri Feb 05 21:48:25 2016 +0300
+++ b/src/http/modules/ngx_http_limit_req_module.c Sun Feb 07 15:03:34 2016 +0600
@@ -53,6 +53,7 @@ typedef struct {
ngx_uint_t limit_log_level;
ngx_uint_t delay_log_level;
ngx_uint_t status_code;
+ ngx_uint_t off; /* unsigned off:1 */
} ngx_http_limit_req_conf_t;
@@ -172,6 +173,10 @@ ngx_http_limit_req_handler(ngx_http_requ
lrcf = ngx_http_get_module_loc_conf(r, ngx_http_limit_req_module);
limits = lrcf->limits.elts;
+ if (lrcf->off) {
+ return NGX_DECLINED;
+ }
+
excess = 0;
rc = NGX_DECLINED;
@@ -698,6 +703,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->off = NGX_CONF_UNSET_UINT;
return conf;
}
@@ -709,7 +715,9 @@ ngx_http_limit_req_merge_conf(ngx_conf_t
ngx_http_limit_req_conf_t *prev = parent;
ngx_http_limit_req_conf_t *conf = child;
- if (conf->limits.elts == NULL) {
+ ngx_conf_merge_uint_value(conf->off, prev->off, 0);
+
+ if (conf->off == 0 && conf->limits.elts == NULL) {
conf->limits = prev->limits;
}
@@ -870,6 +878,31 @@ ngx_http_limit_req(ngx_conf_t *cf, ngx_c
value = cf->args->elts;
+ ngx_conf_merge_uint_value(lrcf->off, lrcf->off, 0);
+
+ if (ngx_strcmp(value[1].data, "off") == 0) {
+ if (cf->args->nelts != 2) {
+ return "has invalid number of arguments";
+ }
+
+ if (lrcf->off || lrcf->limits.elts) {
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+ "\"limit_req off\" cannot be used with other "
+ "\"limit_req\" directives on the same level");
+ return NGX_CONF_ERROR;
+ }
+
+ lrcf->off = 1;
+ return NGX_CONF_OK;
+ }
+
+ if (lrcf->off) {
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+ "\"limit_req off\" cannot be used with other "
+ "\"limit_req\" directives on the same level");
+ return NGX_CONF_ERROR;
+ }
+
shm_zone = NULL;
burst = 0;
nodelay = 0;
More information about the nginx-devel
mailing list