|
| 1 | +diff --git src/http/modules/ngx_http_mirror_module.c src/http/modules/ngx_http_mirror_module.c |
| 2 | +index 787adb3..61d0fd3 100644 |
| 3 | +--- src/http/modules/ngx_http_mirror_module.c |
| 4 | ++++ src/http/modules/ngx_http_mirror_module.c |
| 5 | +@@ -8,10 +8,16 @@ |
| 6 | + #include <ngx_config.h> |
| 7 | + #include <ngx_core.h> |
| 8 | + #include <ngx_http.h> |
| 9 | ++#if (NGX_HTTP_APISIX) |
| 10 | ++#include <ngx_http_apisix_module.h> |
| 11 | ++#endif |
| 12 | + |
| 13 | + |
| 14 | + typedef struct { |
| 15 | + ngx_array_t *mirror; |
| 16 | ++#if (NGX_HTTP_APISIX) |
| 17 | ++ ngx_flag_t on_demand; |
| 18 | ++#endif |
| 19 | + ngx_flag_t request_body; |
| 20 | + } ngx_http_mirror_loc_conf_t; |
| 21 | + |
| 22 | +@@ -33,6 +39,15 @@ static ngx_int_t ngx_http_mirror_init(ngx_conf_t *cf); |
| 23 | + |
| 24 | + static ngx_command_t ngx_http_mirror_commands[] = { |
| 25 | + |
| 26 | ++#if (NGX_HTTP_APISIX) |
| 27 | ++ { ngx_string("apisix_mirror_on_demand"), |
| 28 | ++ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, |
| 29 | ++ ngx_conf_set_flag_slot, |
| 30 | ++ NGX_HTTP_LOC_CONF_OFFSET, |
| 31 | ++ offsetof(ngx_http_mirror_loc_conf_t, on_demand), |
| 32 | ++ NULL }, |
| 33 | ++#endif |
| 34 | ++ |
| 35 | + { ngx_string("mirror"), |
| 36 | + NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
| 37 | + ngx_http_mirror, |
| 38 | +@@ -99,6 +114,12 @@ ngx_http_mirror_handler(ngx_http_request_t *r) |
| 39 | + return NGX_DECLINED; |
| 40 | + } |
| 41 | + |
| 42 | ++#if (NGX_HTTP_APISIX) |
| 43 | ++ if (mlcf->on_demand && !ngx_http_apisix_is_mirror_enabled(r)) { |
| 44 | ++ return NGX_DECLINED; |
| 45 | ++ } |
| 46 | ++#endif |
| 47 | ++ |
| 48 | + ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "mirror handler"); |
| 49 | + |
| 50 | + if (mlcf->request_body) { |
| 51 | +@@ -186,6 +207,9 @@ ngx_http_mirror_create_loc_conf(ngx_conf_t *cf) |
| 52 | + } |
| 53 | + |
| 54 | + mlcf->mirror = NGX_CONF_UNSET_PTR; |
| 55 | ++#if (NGX_HTTP_APISIX) |
| 56 | ++ mlcf->on_demand = NGX_CONF_UNSET; |
| 57 | ++#endif |
| 58 | + mlcf->request_body = NGX_CONF_UNSET; |
| 59 | + |
| 60 | + return mlcf; |
| 61 | +@@ -198,6 +222,9 @@ ngx_http_mirror_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) |
| 62 | + ngx_http_mirror_loc_conf_t *prev = parent; |
| 63 | + ngx_http_mirror_loc_conf_t *conf = child; |
| 64 | + |
| 65 | ++#if (NGX_HTTP_APISIX) |
| 66 | ++ ngx_conf_merge_value(conf->on_demand, prev->on_demand, 0); |
| 67 | ++#endif |
| 68 | + ngx_conf_merge_ptr_value(conf->mirror, prev->mirror, NULL); |
| 69 | + ngx_conf_merge_value(conf->request_body, prev->request_body, 1); |
| 70 | + |
0 commit comments