comparison src/http/modules/ngx_http_mirror_module.c @ 7073:230d16d35ebc

Mirror: "off" paramater of the "mirror" directive.
author Roman Arutyunyan <arut@nginx.com>
date Fri, 21 Jul 2017 19:47:56 +0300
parents 0bb747b2d7cb
children
comparison
equal deleted inserted replaced
7072:0bb747b2d7cb 7073:230d16d35ebc
25 static void ngx_http_mirror_body_handler(ngx_http_request_t *r); 25 static void ngx_http_mirror_body_handler(ngx_http_request_t *r);
26 static ngx_int_t ngx_http_mirror_handler_internal(ngx_http_request_t *r); 26 static ngx_int_t ngx_http_mirror_handler_internal(ngx_http_request_t *r);
27 static void *ngx_http_mirror_create_loc_conf(ngx_conf_t *cf); 27 static void *ngx_http_mirror_create_loc_conf(ngx_conf_t *cf);
28 static char *ngx_http_mirror_merge_loc_conf(ngx_conf_t *cf, void *parent, 28 static char *ngx_http_mirror_merge_loc_conf(ngx_conf_t *cf, void *parent,
29 void *child); 29 void *child);
30 static char *ngx_http_mirror(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
30 static ngx_int_t ngx_http_mirror_init(ngx_conf_t *cf); 31 static ngx_int_t ngx_http_mirror_init(ngx_conf_t *cf);
31 32
32 33
33 static ngx_command_t ngx_http_mirror_commands[] = { 34 static ngx_command_t ngx_http_mirror_commands[] = {
34 35
35 { ngx_string("mirror"), 36 { ngx_string("mirror"),
36 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, 37 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
37 ngx_conf_set_str_array_slot, 38 ngx_http_mirror,
38 NGX_HTTP_LOC_CONF_OFFSET, 39 NGX_HTTP_LOC_CONF_OFFSET,
39 offsetof(ngx_http_mirror_loc_conf_t, mirror), 40 0,
40 NULL }, 41 NULL },
41 42
42 { ngx_string("mirror_request_body"), 43 { ngx_string("mirror_request_body"),
43 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, 44 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
44 ngx_conf_set_flag_slot, 45 ngx_conf_set_flag_slot,
202 203
203 return NGX_CONF_OK; 204 return NGX_CONF_OK;
204 } 205 }
205 206
206 207
208 static char *
209 ngx_http_mirror(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
210 {
211 ngx_http_mirror_loc_conf_t *mlcf = conf;
212
213 ngx_str_t *value, *s;
214
215 value = cf->args->elts;
216
217 if (ngx_strcmp(value[1].data, "off") == 0) {
218 if (mlcf->mirror != NGX_CONF_UNSET_PTR) {
219 return "is duplicate";
220 }
221
222 mlcf->mirror = NULL;
223 return NGX_CONF_OK;
224 }
225
226 if (mlcf->mirror == NULL) {
227 return "is duplicate";
228 }
229
230 if (mlcf->mirror == NGX_CONF_UNSET_PTR) {
231 mlcf->mirror = ngx_array_create(cf->pool, 4, sizeof(ngx_str_t));
232 if (mlcf->mirror == NULL) {
233 return NGX_CONF_ERROR;
234 }
235 }
236
237 s = ngx_array_push(mlcf->mirror);
238 if (s == NULL) {
239 return NGX_CONF_ERROR;
240 }
241
242 *s = value[1];
243
244 return NGX_CONF_OK;
245 }
246
247
207 static ngx_int_t 248 static ngx_int_t
208 ngx_http_mirror_init(ngx_conf_t *cf) 249 ngx_http_mirror_init(ngx_conf_t *cf)
209 { 250 {
210 ngx_http_handler_pt *h; 251 ngx_http_handler_pt *h;
211 ngx_http_core_main_conf_t *cmcf; 252 ngx_http_core_main_conf_t *cmcf;