summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_http_static.c
diff options
context:
space:
mode:
authorAlejandro Colomar <alx.manpages@gmail.com>2021-12-18 22:58:27 +0100
committerAlejandro Colomar <alx.manpages@gmail.com>2022-04-26 12:38:48 +0200
commitbce0f432c402ad18718aecab227b663160682ea4 (patch)
tree01f5091fc6bf12a2deb937b5ad434b65cbe8df62 /src/nxt_http_static.c
parente525605d057fd923aa2728babe5b49e95d86d22b (diff)
downloadunit-bce0f432c402ad18718aecab227b663160682ea4.tar.gz
unit-bce0f432c402ad18718aecab227b663160682ea4.tar.bz2
Removed special cases for non-NXT_CONF_VALUE_ARRAY.
The previous commit added more generic APIs for handling NXT_CONF_VALUE_ARRAY and non-NXT_CONF_VALUE_ARRAY together. Modify calling code to remove special cases for arrays and non-arrays, taking special care that the path for non arrays is logically equivalent to the previous special cased code. Use the now-generic array code only.
Diffstat (limited to 'src/nxt_http_static.c')
-rw-r--r--src/nxt_http_static.c28
1 files changed, 6 insertions, 22 deletions
diff --git a/src/nxt_http_static.c b/src/nxt_http_static.c
index 36c1ebc9..5231f98e 100644
--- a/src/nxt_http_static.c
+++ b/src/nxt_http_static.c
@@ -77,7 +77,6 @@ nxt_http_static_init(nxt_task_t *task, nxt_router_temp_conf_t *tmcf,
nxt_mp_t *mp;
nxt_str_t str;
nxt_var_t *var;
- nxt_bool_t array;
nxt_conf_value_t *cv;
nxt_http_static_conf_t *conf;
@@ -91,39 +90,24 @@ nxt_http_static_init(nxt_task_t *task, nxt_router_temp_conf_t *tmcf,
action->handler = nxt_http_static;
action->u.conf = conf;
- array = (nxt_conf_type(acf->share) == NXT_CONF_ARRAY);
- conf->nshares = array ? nxt_conf_array_elements_count(acf->share) : 1;
-
+ conf->nshares = nxt_conf_array_elements_count_or_1(acf->share);
conf->shares = nxt_mp_zget(mp, sizeof(nxt_http_static_share_t)
* conf->nshares);
if (nxt_slow_path(conf->shares == NULL)) {
return NXT_ERROR;
}
- if (array) {
- for (i = 0; i < conf->nshares; i++) {
- cv = nxt_conf_get_array_element(acf->share, i);
- nxt_conf_get_string(cv, &str);
-
- var = nxt_var_compile(&str, mp, 1);
- if (nxt_slow_path(var == NULL)) {
- return NXT_ERROR;
- }
-
- conf->shares[i].var = var;
- conf->shares[i].is_const = nxt_var_is_const(var);
- }
-
- } else {
- nxt_conf_get_string(acf->share, &str);
+ for (i = 0; i < conf->nshares; i++) {
+ cv = nxt_conf_get_array_element_or_itself(acf->share, i);
+ nxt_conf_get_string(cv, &str);
var = nxt_var_compile(&str, mp, 1);
if (nxt_slow_path(var == NULL)) {
return NXT_ERROR;
}
- conf->shares[0].var = var;
- conf->shares[0].is_const = nxt_var_is_const(var);
+ conf->shares[i].var = var;
+ conf->shares[i].is_const = nxt_var_is_const(var);
}
#if (NXT_HAVE_OPENAT2)