TSG-21649 修复client_administrative_area字段乱码问题以及Edit Element处理多json问题
This commit is contained in:
@@ -134,6 +134,18 @@ const char *lua_http_field_read(const struct tfe_http_half * half, const struct
|
||||
return http_head_field_node != NULL ? http_head_field->value : NULL;
|
||||
}
|
||||
|
||||
static void lua_http_headers_clear()
|
||||
{
|
||||
struct lua_http_head_field * http_head_field = NULL; struct lua_http_head_field * http_head_field_peer = NULL;
|
||||
TAILQ_FOREACH_SAFE(http_head_field, &g_tsg_lua_pattern->lua_http_head_list.lua_http_field_list, next, http_head_field_peer)
|
||||
{
|
||||
TAILQ_REMOVE(&g_tsg_lua_pattern->lua_http_head_list.lua_http_field_list, http_head_field, next);
|
||||
http_field_name_destory(http_head_field->field);
|
||||
free(http_head_field->value);
|
||||
free(http_head_field);
|
||||
}
|
||||
}
|
||||
|
||||
static int lua_http_default_headers_init(struct def_lua_http_headers *lua_http_head_value)
|
||||
{
|
||||
for(size_t i=0; i < sizeof(def_lua_http_head_value)/sizeof(struct def_lua_http_headers); i++)
|
||||
@@ -154,8 +166,8 @@ static int lua_http_default_headers_init(struct def_lua_http_headers *lua_http_h
|
||||
int http_lua_profile_for_test(int profile_id, struct elua_script ***elua_ctx, char **profile_msg, size_t *msg_len, int *timeout)
|
||||
{
|
||||
size_t input_sz;
|
||||
const char* filename="./test_data/http_session.lua";
|
||||
char *input= tfe_read_file(filename, &input_sz);
|
||||
const char *filename[]= {"./test_data/http_session.lua", "./test_data/header_filter_by_lua.lua"};
|
||||
char *input= tfe_read_file(filename[profile_id], &input_sz);
|
||||
|
||||
*profile_msg=tfe_strdup(input);
|
||||
*msg_len=input_sz;
|
||||
@@ -341,8 +353,12 @@ TEST(TSG_LUA_SCRIPT, Req_Data)
|
||||
ASSERT_TRUE(tsg_ctx.http_lua_body!=NULL);
|
||||
|
||||
char *__http_body=(char *) evbuffer_pullup(tsg_ctx.http_lua_body, -1);
|
||||
EXPECT_STREQ(__http_body, "This is request data set req body");
|
||||
printf("__http_body: %s\n",__http_body);
|
||||
size_t __http_body_len = evbuffer_get_length(tsg_ctx.http_lua_body);
|
||||
char __http_body_tmp[__http_body_len+1];
|
||||
memset(__http_body_tmp, 0, sizeof(__http_body_tmp));
|
||||
memcpy(__http_body_tmp, __http_body, __http_body_len);
|
||||
EXPECT_STREQ(__http_body_tmp, "This is request data set req body");
|
||||
printf("__http_body: %s\n",__http_body_tmp);
|
||||
|
||||
evbuffer_free(tsg_ctx.http_body);
|
||||
evbuffer_free(tsg_ctx.http_lua_body);
|
||||
@@ -356,7 +372,7 @@ TEST(TSG_LUA_SCRIPT, Req_Data)
|
||||
TEST(TSG_LUA_SCRIPT, Resq_Data)
|
||||
{
|
||||
int ret=0;
|
||||
int profile_id=3,thread_id=0;
|
||||
int profile_id=0,thread_id=0;
|
||||
struct tsg_script_ctx tsg_ctx;
|
||||
memset(&tsg_ctx,0,sizeof(struct tsg_script_ctx));
|
||||
|
||||
@@ -375,8 +391,12 @@ TEST(TSG_LUA_SCRIPT, Resq_Data)
|
||||
ASSERT_TRUE(tsg_ctx.http_lua_body!=NULL);
|
||||
|
||||
char *__http_body=(char *) evbuffer_pullup(tsg_ctx.http_lua_body, -1);
|
||||
EXPECT_STREQ(__http_body, "This is response data set resp body");
|
||||
printf("__http_body: %s\n",__http_body);
|
||||
size_t __http_body_len = evbuffer_get_length(tsg_ctx.http_lua_body);
|
||||
char __http_body_tmp[__http_body_len+1];
|
||||
memset(__http_body_tmp, 0, sizeof(__http_body_tmp));
|
||||
memcpy(__http_body_tmp, __http_body, __http_body_len);
|
||||
EXPECT_STREQ(__http_body_tmp, "This is response data set resp body");
|
||||
printf("__http_body_tmp: %s\n",__http_body_tmp);
|
||||
|
||||
evbuffer_free(tsg_ctx.http_body);
|
||||
evbuffer_free(tsg_ctx.http_lua_body);
|
||||
@@ -418,8 +438,12 @@ TEST(TSG_LUA_SCRIPT, Lua_Http_Session)
|
||||
EXPECT_TRUE(tsg_ctx.http_lua_body!=NULL);
|
||||
|
||||
char *__http_body=(char *) evbuffer_pullup(tsg_ctx.http_lua_body, -1);
|
||||
EXPECT_STREQ(__http_body, "This is response data set resp body");
|
||||
printf("__http_body: %s\n",__http_body);
|
||||
size_t __http_body_len = evbuffer_get_length(tsg_ctx.http_lua_body);
|
||||
char __http_body_tmp[__http_body_len+1];
|
||||
memset(__http_body_tmp, 0, sizeof(__http_body_tmp));
|
||||
memcpy(__http_body_tmp, __http_body, __http_body_len);
|
||||
EXPECT_STREQ(__http_body_tmp, "This is response data set resp body");
|
||||
printf("__http_body: %s\n",__http_body_tmp);
|
||||
|
||||
evbuffer_free(tsg_ctx.http_body);
|
||||
evbuffer_free(tsg_ctx.http_lua_body);
|
||||
@@ -431,6 +455,53 @@ TEST(TSG_LUA_SCRIPT, Lua_Http_Session)
|
||||
lua_http_session_destory((struct tfe_http_session *)tsg_ctx.session);
|
||||
}
|
||||
|
||||
TEST(TSG_LUA_SCRIPT, Lua_Http_Header_Filter)
|
||||
{
|
||||
int ret=0;
|
||||
int profile_id=1,thread_id=0;
|
||||
struct tsg_script_ctx tsg_ctx;
|
||||
memset(&tsg_ctx,0,sizeof(struct tsg_script_ctx));
|
||||
|
||||
tsg_ctx.session=lua_http_session_init();
|
||||
tsg_ctx.events = EV_HTTP_RESP_HDR;
|
||||
|
||||
struct tsg_lua_script * lua_script=g_tsg_lua_pattern->lua_script;
|
||||
lua_script->http_lua_profile = http_lua_profile_for_test;
|
||||
tsg_ctx.elua_ctx=http_lua_ctx_new(lua_script, thread_id);
|
||||
|
||||
lua_http_headers_clear();
|
||||
tsg_ctx.replacing=tsg_ctx.session->resp;
|
||||
ret = execute_lua_script_rule(lua_script, profile_id, tsg_ctx.elua_ctx, thread_id, (void *)&tsg_ctx);
|
||||
EXPECT_TRUE(ret==0);
|
||||
|
||||
const char *server_type_val=tfe_http_std_field_read(tsg_ctx.replacing, TFE_HTTP_SERVER);
|
||||
EXPECT_TRUE(server_type_val!=NULL);
|
||||
EXPECT_STREQ(server_type_val, "nqinx");
|
||||
const char *location_type_val=tfe_http_std_field_read(tsg_ctx.replacing, TFE_HTTP_LOCATION);
|
||||
EXPECT_TRUE(location_type_val!=NULL);
|
||||
printf("location:%s\n",location_type_val);
|
||||
const char *date_type_val=tfe_http_std_field_read(tsg_ctx.replacing, TFE_HTTP_DATE);
|
||||
EXPECT_TRUE(date_type_val!=NULL);
|
||||
printf("date:%s\n",date_type_val);
|
||||
|
||||
tsg_ctx.events = EV_HTTP_RESP_BODY_END;
|
||||
tsg_ctx.http_body = evbuffer_new();
|
||||
const char *user_input="This is response data";
|
||||
evbuffer_add(tsg_ctx.http_body, user_input, strlen(user_input));
|
||||
|
||||
ret = execute_lua_script_rule(lua_script, profile_id, tsg_ctx.elua_ctx, thread_id, (void *)&tsg_ctx);
|
||||
EXPECT_TRUE(ret==0);
|
||||
EXPECT_TRUE(tsg_ctx.http_lua_body!=NULL);
|
||||
char *__http_body=(char *) evbuffer_pullup(tsg_ctx.http_lua_body, -1);
|
||||
EXPECT_TRUE(__http_body!=NULL);
|
||||
|
||||
elua_cleanup_script(g_tsg_lua_pattern->elua_ctx[thread_id]);
|
||||
FREE(&g_tsg_lua_pattern->elua_ctx[thread_id]);
|
||||
g_tsg_lua_pattern->elua_ctx[thread_id]=NULL;
|
||||
http_lua_ctx_free(lua_script, thread_id, tsg_ctx.elua_ctx);
|
||||
lua_http_session_destory((struct tfe_http_session *)tsg_ctx.session);
|
||||
}
|
||||
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
struct tsg_lua_pattern *tsg_lua_pattern = ALLOC(struct tsg_lua_pattern, 1);
|
||||
|
||||
Reference in New Issue
Block a user