Skip to content

Multiple response headers grouped into table #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 29 additions & 7 deletions src/ngx_http_lua_contentby.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* vim:set ft=c ts=4 sw=4 et fdm=marker: */
#define DDEBUG 0
#define DDEBUG 3

#include "ngx_http_lua_contentby.h"
#include "ngx_http_lua_util.h"
Expand Down Expand Up @@ -366,13 +366,35 @@ ngx_http_lua_wev_handler(ngx_http_request_t *r)
continue;
}
#endif


// push header key on stack
lua_pushlstring(cc, (char *) header[i].key.data,
header[i].key.len); /* header key */

lua_pushlstring(cc, (char *) header[i].value.data,
header[i].value.len); /* header key value */

header[i].key.len); /* header key */

// check if header exists
u_char *header_key = ngx_pcalloc(r->pool, header[i].key.len + 1);
ngx_copy(header_key, header[i].key.data, header[i].key.len);
lua_getfield(cc, -2, (const char *)header_key);

int value_type = lua_type(cc, -1);

if (value_type != LUA_TNIL) {
if (value_type != LUA_TTABLE) {
lua_pop(cc, 1);
lua_newtable(cc);
lua_getfield(cc, -2, (const char *)header_key);
lua_rawseti(cc, -2, 1);
}
lua_pushlstring(cc, (char *) header[i].value.data,
header[i].value.len); /* header key value */
lua_rawseti(cc, -2, lua_objlen(cc, -2) + 1);
} else {
lua_pop(cc, 1);

lua_pushlstring(cc, (char *) header[i].value.data,
header[i].value.len); /* header key value */
}

lua_rawset(cc, -3); /* head */
}

Expand Down