Skip to content

Commit 9a613f7

Browse files
committed
Implemented configuration switching
1 parent 7b7f947 commit 9a613f7

File tree

3 files changed

+38
-22
lines changed

3 files changed

+38
-22
lines changed

ngx_http_upload.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ struct ngx_http_upload_loc_conf_s;
9595

9696
typedef struct {
9797
ngx_str_t content_type;
98-
struct ngx_http_upload_loc_conf_s *conf;
98+
ngx_http_core_loc_conf_t *conf;
9999
} ngx_upload_content_type_map_t;
100100

101101
/*
@@ -180,6 +180,7 @@ typedef struct ngx_http_upload_ctx_s {
180180

181181
ngx_http_request_t *request;
182182
ngx_log_t *log;
183+
void **original_loc_conf;
183184

184185
ngx_file_t output_file;
185186
ngx_chain_t *chain;

ngx_http_upload_module.c

+35-20
Original file line numberDiff line numberDiff line change
@@ -1592,7 +1592,7 @@ ngx_http_upload_cleanup(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
15921592

15931593
static ngx_uint_t /* {{{ ngx_http_upload_add_slave_conf */
15941594
ngx_http_upload_add_slave_conf(ngx_str_t *content_type, ngx_array_t **content_type_map,
1595-
ngx_http_upload_loc_conf_t *ulcf, ngx_pool_t *pool)
1595+
ngx_http_core_loc_conf_t *clcf, ngx_pool_t *pool)
15961596
{
15971597
ngx_upload_content_type_map_t *ctmap;
15981598

@@ -1610,7 +1610,7 @@ ngx_http_upload_add_slave_conf(ngx_str_t *content_type, ngx_array_t **content_ty
16101610
}
16111611

16121612
ctmap->content_type = *content_type;
1613-
ctmap->conf = ulcf;
1613+
ctmap->conf = clcf;
16141614

16151615
return NGX_OK;
16161616
} /* }}} */
@@ -1691,21 +1691,21 @@ ngx_http_upload_filter_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
16911691

16921692
ulcf->parent = pulcf;
16931693

1694-
for (i = 1; i < cf->args->nelts; i++) {
1695-
if(ngx_http_upload_add_slave_conf(&value[i], &pulcf->content_type_map,
1696-
ulcf, cf->pool) != NGX_OK)
1697-
{
1698-
return NGX_CONF_ERROR;
1699-
}
1700-
}
1701-
17021694
pclcf = pctx->loc_conf[ngx_http_core_module.ctx_index];
17031695

17041696
clcf = ctx->loc_conf[ngx_http_core_module.ctx_index];
17051697
clcf->loc_conf = ctx->loc_conf;
17061698
clcf->name = pclcf->name;
17071699
clcf->noname = 1;
17081700

1701+
for (i = 1; i < cf->args->nelts; i++) {
1702+
if(ngx_http_upload_add_slave_conf(&value[i], &pulcf->content_type_map,
1703+
clcf, cf->pool) != NGX_OK)
1704+
{
1705+
return NGX_CONF_ERROR;
1706+
}
1707+
}
1708+
17091709
if (ngx_http_add_location(cf, &pclcf->locations, clcf) != NGX_OK) {
17101710
return NGX_CONF_ERROR;
17111711
}
@@ -1741,7 +1741,7 @@ ngx_http_upload_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
17411741
return NGX_CONF_OK;
17421742
} /* }}} */
17431743

1744-
ngx_upload_field_filter_t* /* {{{ ngx_upload_get_next_content_filter */
1744+
ngx_upload_field_filter_t* /* {{{ ngx_upload_get_next_field_filter */
17451745
ngx_upload_get_next_field_filter(ngx_http_upload_ctx_t *ctx) {
17461746
return &ngx_write_field_filter;
17471747
} /* }}} */
@@ -2314,27 +2314,36 @@ static ngx_int_t /* {{{ ngx_upload_set_content_filter */
23142314
ngx_upload_set_content_filter(ngx_http_upload_ctx_t *u, ngx_str_t *content_type)
23152315
{
23162316
ngx_uint_t i;
2317-
ngx_http_upload_loc_conf_t *ulcf;
2317+
ngx_http_upload_loc_conf_t *pulcf, *ulcf;
23182318
ngx_upload_content_type_map_t *ulctm;
23192319

2320-
ulcf = ngx_http_get_module_loc_conf(u->request, ngx_http_upload_module);
2320+
pulcf = ngx_http_get_module_loc_conf(u->request, ngx_http_upload_module);
2321+
2322+
if(pulcf->parent) {
2323+
pulcf = pulcf->parent;
2324+
}
23212325

23222326
u->current_content_filter_idx = 0;
23232327

2324-
if (content_type->len && ulcf->content_type_map != NULL) {
2325-
for (i = 0; i < ulcf->content_type_map->nelts; i++) {
2326-
ulctm = ulcf->content_type_map->elts;
2328+
if (content_type->len && pulcf->content_type_map != NULL) {
2329+
ulctm = pulcf->content_type_map->elts;
2330+
for (i = 0; i < pulcf->content_type_map->nelts; i++) {
2331+
2332+
if(ngx_strncasecmp(ulctm[i].content_type.data, content_type->data, content_type->len) == 0) {
2333+
/*
2334+
* Got to slave configuration
2335+
*/
2336+
u->request->loc_conf = ulctm[i].conf->loc_conf;
23272337

2328-
ulctm += i;
2338+
ulcf = ngx_http_get_module_loc_conf(u->request, ngx_http_upload_module);
23292339

2330-
if(ngx_strcmp(ulctm->content_type.data, content_type->data) == 0) {
2331-
u->current_content_filter_chain = ulctm->conf->content_filters;
2340+
u->current_content_filter_chain = ulcf->content_filters;
23322341
return NGX_OK;
23332342
}
23342343
}
23352344
}
23362345

2337-
u->current_content_filter_chain = ulcf->content_filters;
2346+
u->current_content_filter_chain = pulcf->content_filters;
23382347

23392348
return NGX_OK;
23402349
} /* }}} */
@@ -2358,6 +2367,8 @@ static ngx_int_t upload_start_part(ngx_http_upload_ctx_t *upload_ctx) { /* {{{ *
23582367
upload_ctx->content_type = content_type;
23592368
}
23602369

2370+
upload_ctx->original_loc_conf = upload_ctx->request->loc_conf;
2371+
23612372
ngx_upload_set_content_filter(upload_ctx, &upload_ctx->content_type);
23622373

23632374
cflt = ngx_upload_get_next_content_filter(upload_ctx);
@@ -2391,6 +2402,8 @@ static void upload_finish_part(ngx_http_upload_ctx_t *upload_ctx) { /* {{{ */
23912402
upload_discard_part_attributes(upload_ctx);
23922403

23932404
upload_ctx->discard_data = 0;
2405+
2406+
upload_ctx->request->loc_conf = upload_ctx->original_loc_conf;
23942407
} /* }}} */
23952408

23962409
static void upload_abort_part(ngx_http_upload_ctx_t *upload_ctx) { /* {{{ */
@@ -2400,6 +2413,8 @@ static void upload_abort_part(ngx_http_upload_ctx_t *upload_ctx) { /* {{{ */
24002413
upload_discard_part_attributes(upload_ctx);
24012414

24022415
upload_ctx->discard_data = 0;
2416+
2417+
upload_ctx->request->loc_conf = upload_ctx->original_loc_conf;
24032418
} /* }}} */
24042419

24052420
static void upload_flush_output_buffer(ngx_http_upload_ctx_t *upload_ctx) { /* {{{ */

ngx_upload_unzip_filter_module.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,7 @@ ngx_upload_unzip_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
964964

965965
ngx_conf_merge_size_value(conf->max_file_name_len,
966966
prev->max_file_name_len,
967-
(size_t) 256);
967+
(size_t) 512);
968968

969969
return NGX_CONF_OK;
970970
} /* }}} */

0 commit comments

Comments
 (0)