Update ngx_http_limit_req_module.c

add "r/h"(request per hour), "r/d"(request per day) support
This commit is contained in:
FJEagle 2024-09-14 14:14:19 +08:00 committed by fjeagle
parent 4b76b142c7
commit fa616921f9

View File

@ -16,7 +16,7 @@
#define NGX_HTTP_LIMIT_REQ_DELAYED_DRY_RUN 4
#define NGX_HTTP_LIMIT_REQ_REJECTED_DRY_RUN 5
#define NGX_HTTP_LIMIT_REQ_RATE_SCALE_MULTIPLIER 1000
#define NGX_HTTP_LIMIT_REQ_RATE_SCALE_MULTIPLIER 1000000
typedef struct {
@ -25,7 +25,7 @@ typedef struct {
u_short len;
ngx_queue_t queue;
ngx_msec_t last;
/* integer value, 1 corresponds to 0.001 r/s */
/* integer value, 1 corresponds to 0.000001 r/s */
ngx_uint_t excess;
ngx_uint_t count;
u_char data[1];
@ -42,7 +42,7 @@ typedef struct {
typedef struct {
ngx_http_limit_req_shctx_t *sh;
ngx_slab_pool_t *shpool;
/* integer value, 1 corresponds to 0.001 r/s */
/* integer value, 1 corresponds to 0.000001 r/s */
ngx_uint_t rate;
ngx_http_complex_value_t key;
ngx_http_limit_req_node_t *node;
@ -51,7 +51,7 @@ typedef struct {
typedef struct {
ngx_shm_zone_t *shm_zone;
/* integer value, 1 corresponds to 0.001 r/s */
/* integer value, 1 corresponds to 0.000001 r/s */
ngx_uint_t burst;
ngx_uint_t delay;
} ngx_http_limit_req_limit_t;
@ -914,6 +914,12 @@ ngx_http_limit_req_zone(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
} else if (ngx_strncmp(p, "r/m", 3) == 0) {
scale = 60;
len -= 3;
} else if (ngx_strncmp(p, "r/h", 3) == 0) {
scale = 3600;
len -= 3;
} else if (ngx_strncmp(p, "r/d", 3) == 0) {
scale = 86400;
len -= 3;
}
rate = ngx_atoi(value[i].data + 5, len - 5);