diff --git a/README.md b/README.md index ae9d0b7..2167e0a 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ protocol. * [upload_store_access](#upload_store_access) * [upload_set_form_field](#upload_set_form_field) * [upload_aggregate_form_field](#upload_aggregate_form_field) + * [upload_pass_form_field_default](#upload_pass_form_field_default) * [upload_pass_form_field](#upload_pass_form_field) * [upload_cleanup](#upload_cleanup) * [upload_buffer_size](#upload_buffer_size) @@ -169,6 +170,16 @@ upload_aggregate_form_field $upload_field_name.size "$upload_file_size"; ``` +### upload_pass_form_field_default + +**Syntax:** upload_pass_form_field_default on | off
+**Default:** `upload_pass_form_field_default off`
+**Context:** `main,server,location` + +Specifies whether fields will be passed to backend from original request +body by default or not. By default, they will not be passed unless there +is a match with [upload_pass_form_field](#upload_pass_form_field). + ### upload_pass_form_field **Syntax:** upload_pass_form_field regex
@@ -180,7 +191,8 @@ backend from original request body. This directive could be specified multiple times per location. Field will be passed to backend as soon as first pattern matches. For PCRE-unaware enviroments this directive specifies exact name of a field to pass to backend. If directive is -omitted, no fields will be passed to backend from client. +omitted, fields will be passed to backend from client depending on the +value of [upload_pass_form_field_default](#upload_pass_form_field_default). Usage example: diff --git a/ngx_http_upload_module.c b/ngx_http_upload_module.c index c51429f..e5dfa51 100644 --- a/ngx_http_upload_module.c +++ b/ngx_http_upload_module.c @@ -178,6 +178,7 @@ typedef struct { ngx_flag_t forward_args; ngx_flag_t tame_arrays; ngx_flag_t resumable_uploads; + ngx_flag_t upload_pass_form_field_default; ngx_flag_t empty_field_names; size_t limit_rate; @@ -581,6 +582,17 @@ static ngx_command_t ngx_http_upload_commands[] = { /* {{{ */ offsetof(ngx_http_upload_loc_conf_t, aggregate_field_templates), NULL}, + /* + * Specifies whether to pass fields to backend by default + */ + { ngx_string("upload_pass_form_field_default"), + NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LMT_CONF|NGX_HTTP_LIF_CONF + |NGX_CONF_FLAG, + ngx_conf_set_flag_slot, + NGX_HTTP_LOC_CONF_OFFSET, + offsetof(ngx_http_upload_loc_conf_t, upload_pass_form_field_default), + NULL }, + /* * Specifies the field to pass to backend */ @@ -1557,6 +1569,10 @@ static ngx_int_t ngx_http_upload_start_handler(ngx_http_upload_ctx_t *u) { /* {{ }else{ pass_field = 0; + if(ulcf->upload_pass_form_field_default) { + pass_field = 1; + } + if(ulcf->field_filters) { f = ulcf->field_filters->elts; for (i = 0; i < ulcf->field_filters->nelts; i++) { @@ -1582,7 +1598,10 @@ static ngx_int_t ngx_http_upload_start_handler(ngx_http_upload_ctx_t *u) { /* {{ } } - if(pass_field && u->field_name.len != 0) { + ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, + "passing other field \"%V\" = %d", &u->field_name, pass_field); + + if(pass_field && u->field_name.len != 0) { /* * Here we do a small hack: the content of a non-file field * is not known until ngx_http_upload_flush_output_buffer @@ -1592,8 +1611,14 @@ static ngx_int_t ngx_http_upload_start_handler(ngx_http_upload_ctx_t *u) { /* {{ if(rc != NGX_OK) return rc; - }else + }else{ + ngx_log_error(NGX_LOG_INFO, r->connection->log, 0 + , "discarding other form field \"%V\"" + , &u->field_name + ); + u->discard_data = 1; + } } @@ -2218,6 +2243,7 @@ ngx_http_upload_create_loc_conf(ngx_conf_t *cf) conf->tame_arrays = NGX_CONF_UNSET; conf->resumable_uploads = NGX_CONF_UNSET; conf->empty_field_names = NGX_CONF_UNSET; + conf->upload_pass_form_field_default = NGX_CONF_UNSET; conf->buffer_size = NGX_CONF_UNSET_SIZE; conf->merge_buffer_size = NGX_CONF_UNSET_SIZE; @@ -2305,6 +2331,11 @@ ngx_http_upload_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) prev->resumable_uploads : 0; } + if(conf->upload_pass_form_field_default == NGX_CONF_UNSET) { + conf->upload_pass_form_field_default = (prev->upload_pass_form_field_default != NGX_CONF_UNSET) ? + prev->upload_pass_form_field_default : 0; + } + if(conf->empty_field_names == NGX_CONF_UNSET) { conf->empty_field_names = (prev->empty_field_names != NGX_CONF_UNSET) ? prev->empty_field_names : 0;