applied a modified version of neilljordan 's patch to add support for multi-value response headers returned from subrquests.
This commit is contained in:
Родитель
9a7c06c4a8
Коммит
44bbe7068d
|
@ -620,7 +620,17 @@ Here's a basic example:
|
|||
Returns a Lua table with three slots (`res.status`, `res.header`, and `res.body`).
|
||||
|
||||
`res.header` holds all the response headers of the
|
||||
subrequest and it is a normal Lua table.
|
||||
subrequest and it is a normal Lua table. For multi-value response headers,
|
||||
the value is a Lua (array) table that holds all the values in the order that
|
||||
they appear. For instance, if the subrequest response headers contains the following
|
||||
lines:
|
||||
|
||||
Set-Cookie: a=3
|
||||
Set-Cookie: foo=bar
|
||||
Set-Cookie: baz=blah
|
||||
|
||||
Then `res.header["Set-Cookie"]` will be evaluted to the table value
|
||||
`{"a=3", "foo=bar", "baz=blah"}`.
|
||||
|
||||
URI query strings can be concatenated to URI itself, for instance,
|
||||
|
||||
|
|
|
@ -1178,11 +1178,40 @@ ngx_http_lua_wev_handler(ngx_http_request_t *r)
|
|||
|
||||
lua_pushlstring(cc, (char *) header[i].key.data,
|
||||
header[i].key.len); /* header key */
|
||||
lua_pushvalue(cc, -1); /* stack: table key key */
|
||||
|
||||
lua_pushlstring(cc, (char *) header[i].value.data,
|
||||
header[i].value.len); /* header key value */
|
||||
/* check if header already exists */
|
||||
lua_rawget(cc, -3); /* stack: table key value */
|
||||
|
||||
lua_rawset(cc, -3); /* head */
|
||||
if (lua_isnil(cc, -1)) {
|
||||
lua_pop(cc, 1); /* stack: table key */
|
||||
|
||||
lua_pushlstring(cc, (char *) header[i].value.data,
|
||||
header[i].value.len); /* stack: table key value */
|
||||
|
||||
lua_rawset(cc, -3); /* stack: table */
|
||||
|
||||
} else {
|
||||
if (! lua_istable(cc, -1)) { /* already inserted one value */
|
||||
lua_createtable(cc, 4, 0); /* stack: table key value table */
|
||||
lua_insert(cc, -2); /* stack: table key table value */
|
||||
lua_rawseti(cc, -2, 1); /* stack: table key table */
|
||||
|
||||
lua_pushlstring(cc, (char *) header[i].value.data,
|
||||
header[i].value.len); /* stack: table key table value */
|
||||
|
||||
lua_rawseti(cc, -2, lua_objlen(cc, -2) + 1); /* stack: table key table */
|
||||
|
||||
lua_rawset(cc, -3); /* stack: table */
|
||||
|
||||
} else {
|
||||
lua_pushlstring(cc, (char *) header[i].value.data,
|
||||
header[i].value.len); /* stack: table key table value */
|
||||
|
||||
lua_rawseti(cc, -2, lua_objlen(cc, -2) + 1); /* stack: table key table */
|
||||
lua_pop(cc, 2); /* stack: table */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lua_setfield(cc, -2, "header");
|
||||
|
|
|
@ -405,7 +405,34 @@ type: foo/bar
|
|||
|
||||
|
||||
|
||||
=== TEST 24: capture location headers
|
||||
=== TEST 24: capture location multi-value headers
|
||||
--- config
|
||||
location /other {
|
||||
#echo "hello, world";
|
||||
content_by_lua '
|
||||
ngx.header["Set-Cookie"] = {"a", "hello, world", "foo"}
|
||||
ngx.eof()
|
||||
';
|
||||
}
|
||||
|
||||
location /lua {
|
||||
content_by_lua '
|
||||
res = ngx.location.capture("/other");
|
||||
ngx.say("type: ", type(res.header["Set-Cookie"]));
|
||||
ngx.say("len: ", #res.header["Set-Cookie"]);
|
||||
ngx.say("value: ", table.concat(res.header["Set-Cookie"], "|"))
|
||||
';
|
||||
}
|
||||
--- request
|
||||
GET /lua
|
||||
--- response_body
|
||||
type: table
|
||||
len: 3
|
||||
value: a|hello, world|foo
|
||||
|
||||
|
||||
|
||||
=== TEST 25: capture location headers
|
||||
--- config
|
||||
location /other {
|
||||
default_type 'foo/bar';
|
||||
|
@ -429,7 +456,7 @@ Bar: Bah
|
|||
|
||||
|
||||
|
||||
=== TEST 25: capture location headers
|
||||
=== TEST 26: capture location headers
|
||||
--- config
|
||||
location /other {
|
||||
default_type 'foo/bar';
|
||||
|
|
Загрузка…
Ссылка в новой задаче