aboutsummaryrefslogtreecommitdiff
path: root/src/http/modules/ngx_http_scgi_module.c
diff options
context:
space:
mode:
authorValentin Bartenev <vbart@nginx.com>2011-12-09 14:03:06 +0000
committerValentin Bartenev <vbart@nginx.com>2011-12-09 14:03:06 +0000
commitdf54c36d90ff0bdebe7adba5de582072f9af69f8 (patch)
tree15025f00fec8ff24c1c7d7a0d3d297c8184a98f5 /src/http/modules/ngx_http_scgi_module.c
parent582b5319b7bff11ce17a194742ed75310dbc8c93 (diff)
downloadnginx-df54c36d90ff0bdebe7adba5de582072f9af69f8.tar.gz
nginx-df54c36d90ff0bdebe7adba5de582072f9af69f8.zip
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
Diffstat (limited to 'src/http/modules/ngx_http_scgi_module.c')
-rw-r--r--src/http/modules/ngx_http_scgi_module.c74
1 files changed, 60 insertions, 14 deletions
diff --git a/src/http/modules/ngx_http_scgi_module.c b/src/http/modules/ngx_http_scgi_module.c
index 168f497ce..41cf23bc6 100644
--- a/src/http/modules/ngx_http_scgi_module.c
+++ b/src/http/modules/ngx_http_scgi_module.c
@@ -278,8 +278,8 @@ static ngx_command_t ngx_http_scgi_commands[] = {
&ngx_http_scgi_next_upstream_masks },
{ ngx_string("scgi_param"),
- NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE2,
- ngx_conf_set_keyval_slot,
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE23,
+ ngx_http_upstream_param_set_slot,
NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_scgi_loc_conf_t, params_source),
NULL },
@@ -519,10 +519,10 @@ static ngx_int_t
ngx_http_scgi_create_request(ngx_http_request_t *r)
{
u_char ch, *key, *val, *lowcase_key;
- size_t len, allocated;
+ size_t len, key_len, val_len, allocated;
ngx_buf_t *b;
ngx_str_t *content_length;
- ngx_uint_t i, n, hash, header_params;
+ ngx_uint_t i, n, hash, skip_empty, header_params;
ngx_chain_t *cl, *body;
ngx_list_part_t *part;
ngx_table_elt_t *header, **ignored;
@@ -554,15 +554,21 @@ ngx_http_scgi_create_request(ngx_http_request_t *r)
while (*(uintptr_t *) le.ip) {
lcode = *(ngx_http_script_len_code_pt *) le.ip;
- len += lcode(&le);
+ key_len = lcode(&le);
+
+ lcode = *(ngx_http_script_len_code_pt *) le.ip;
+ skip_empty = lcode(&le);
- while (*(uintptr_t *) le.ip) {
+ for (val_len = 0; *(uintptr_t *) le.ip; val_len += lcode(&le)) {
lcode = *(ngx_http_script_len_code_pt *) le.ip;
- len += lcode(&le);
}
- len++;
-
le.ip += sizeof(uintptr_t);
+
+ if (skip_empty && val_len == 0) {
+ continue;
+ }
+
+ len += key_len + val_len + 1;
}
}
@@ -665,7 +671,34 @@ ngx_http_scgi_create_request(ngx_http_request_t *r)
e.request = r;
e.flushed = 1;
- while (*(uintptr_t *) e.ip) {
+ le.ip = scf->params_len->elts;
+
+ while (*(uintptr_t *) le.ip) {
+
+ lcode = *(ngx_http_script_len_code_pt *) le.ip;
+ lcode(&le); /* key length */
+
+ lcode = *(ngx_http_script_len_code_pt *) le.ip;
+ skip_empty = lcode(&le);
+
+ for (val_len = 0; *(uintptr_t *) le.ip; val_len += lcode(&le)) {
+ lcode = *(ngx_http_script_len_code_pt *) le.ip;
+ }
+ le.ip += sizeof(uintptr_t);
+
+ if (skip_empty && val_len == 0) {
+ e.skip = 1;
+
+ while (*(uintptr_t *) e.ip) {
+ code = *(ngx_http_script_code_pt *) e.ip;
+ code((ngx_http_script_engine_t *) &e);
+ }
+ e.ip += sizeof(uintptr_t);
+
+ e.skip = 0;
+
+ continue;
+ }
#if (NGX_DEBUG)
key = e.pos;
@@ -1323,9 +1356,9 @@ ngx_http_scgi_merge_params(ngx_conf_t *cf, ngx_http_scgi_loc_conf_t *conf,
#if (NGX_HTTP_CACHE)
ngx_array_t params_merged;
#endif
- ngx_keyval_t *src;
ngx_hash_key_t *hk;
ngx_hash_init_t hash;
+ ngx_http_upstream_param_t *src;
ngx_http_script_compile_t sc;
ngx_http_script_copy_code_t *copy;
@@ -1386,9 +1419,11 @@ ngx_http_scgi_merge_params(ngx_conf_t *cf, ngx_http_scgi_loc_conf_t *conf,
#if (NGX_HTTP_CACHE)
if (conf->upstream.cache) {
- ngx_keyval_t *h, *s;
+ ngx_keyval_t *h;
+ ngx_http_upstream_param_t *s;
- if (ngx_array_init(&params_merged, cf->temp_pool, 4, sizeof(ngx_keyval_t))
+ if (ngx_array_init(&params_merged, cf->temp_pool, 4,
+ sizeof(ngx_http_upstream_param_t))
!= NGX_OK)
{
return NGX_ERROR;
@@ -1422,7 +1457,9 @@ ngx_http_scgi_merge_params(ngx_conf_t *cf, ngx_http_scgi_loc_conf_t *conf,
return NGX_ERROR;
}
- *s = *h;
+ s->key = h->key;
+ s->value = h->value;
+ s->skip_empty = 0;
next:
@@ -1464,6 +1501,15 @@ ngx_http_scgi_merge_params(ngx_conf_t *cf, ngx_http_scgi_loc_conf_t *conf,
copy->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code;
copy->len = src[i].key.len + 1;
+ copy = ngx_array_push_n(conf->params_len,
+ sizeof(ngx_http_script_copy_code_t));
+ if (copy == NULL) {
+ return NGX_ERROR;
+ }
+
+ copy->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code;
+ copy->len = src[i].skip_empty;
+
size = (sizeof(ngx_http_script_copy_code_t)
+ src[i].key.len + 1 + sizeof(uintptr_t) - 1)