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;
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
};
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--) {
ctx->node = NULL;
}
+ if (lrcf->dry_run) {
+ return NGX_DECLINED;
+ }
+
return lrcf->status_code;
}
}
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;
}
conf->limit_log_level = NGX_CONF_UNSET_UINT;
conf->status_code = NGX_CONF_UNSET_UINT;
+ conf->dry_run = NGX_CONF_UNSET;
return conf;
}
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;
}