summaryrefslogtreecommitdiff
path: root/plugin/protocol/http2
diff options
context:
space:
mode:
Diffstat (limited to 'plugin/protocol/http2')
-rw-r--r--plugin/protocol/http2/src/http2_stream.cpp3
-rw-r--r--plugin/protocol/http2/test/test_http2_stream.cpp133
2 files changed, 79 insertions, 57 deletions
diff --git a/plugin/protocol/http2/src/http2_stream.cpp b/plugin/protocol/http2/src/http2_stream.cpp
index 58c1f6b..96a97b3 100644
--- a/plugin/protocol/http2/src/http2_stream.cpp
+++ b/plugin/protocol/http2/src/http2_stream.cpp
@@ -315,7 +315,8 @@ int h2_half_ops_field_write(struct tfe_http_half * half, const struct http_field
continue;
TAILQ_REMOVE(&h2_header->h2_field_list, h2_field, next);
- free(h2_field->nv.name);
+ free(h2_field->field);
+ free(h2_field->nv.name);
free(h2_field->nv.value);
free(h2_field);
h2_header->nvlen--;
diff --git a/plugin/protocol/http2/test/test_http2_stream.cpp b/plugin/protocol/http2/test/test_http2_stream.cpp
index 681ebb9..029986d 100644
--- a/plugin/protocol/http2/test/test_http2_stream.cpp
+++ b/plugin/protocol/http2/test/test_http2_stream.cpp
@@ -118,11 +118,12 @@ void UT_Parse_ReqHeaders(nghttp2_session *as_server)
xret = tfe_http_field_write(tfe_half, &field_name, "201x101x");
EXPECT_EQ(xret, 0);
- field_name.field_id = TFE_HTTP_DATE;
+ field_name.field_id = TFE_HTTP_DATE;
hdr_value = tfe_http_field_read((const struct tfe_http_half*)tfe_half, &field_name);
EXPECT_STREQ(hdr_value, "201x101x");
+ xret = tfe_http_field_write(tfe_half, &field_name, NULL); // delete field_name
- return;
+ return;
}
void UT_Parse_RespHeaders(nghttp2_session *as_client)
@@ -197,6 +198,10 @@ TEST(Http2StreamParser, GetFrameWithMagic)
/*Recv data magic**/
readlen = nghttp2_session_mem_recv(h2_stream_info->as_server, magic_headers, sizeof(magic_headers));
EXPECT_GT(readlen, 0);
+
+ sess_data_ctx_fini(tapinfo->h2_stream_info, NULL, 0);
+ free(tapinfo->h2_stream_info);
+ free(tapinfo);
}
TEST(Http2StreamParser, GetFrameWithHeader_01)
@@ -219,6 +224,10 @@ TEST(Http2StreamParser, GetFrameWithHeader_01)
EXPECT_GT(readlen, 0);
UT_Parse_ReqHeaders(h2_stream_info->as_server);
+
+ sess_data_ctx_fini(tapinfo->h2_stream_info, NULL, 0);
+ free(tapinfo->h2_stream_info);
+ free(tapinfo);
}
TEST(Http2StreamParser, GetFrameWithHeader_02)
@@ -244,6 +253,10 @@ TEST(Http2StreamParser, GetFrameWithHeader_02)
//enum tfe_stream_action stream_action = ACTION_FORWARD_DATA;
//stream_action = nghttp2_client_mem_send(h2_stream_info);
//EXPECT_EQ(stream_action, ACTION_DROP_DATA);
+
+ sess_data_ctx_fini(tapinfo->h2_stream_info, NULL, 0);
+ free(tapinfo->h2_stream_info);
+ free(tapinfo);
}
TEST(Http2StreamParser, RespFrameWithHead_01)
@@ -278,6 +291,10 @@ TEST(Http2StreamParser, RespFrameWithHead_01)
readlen = nghttp2_session_mem_recv(h2_stream_info->as_client, response_header2, sizeof(response_header2));
EXPECT_GT(readlen, 0);
UT_Parse_RespHeaders(h2_stream_info->as_client);
+
+ sess_data_ctx_fini(tapinfo->h2_stream_info, NULL, 0);
+ free(tapinfo->h2_stream_info);
+ free(tapinfo);
}
#endif
@@ -310,49 +327,51 @@ TEST(Http2StreamParser, FrameWithJdData)
action = detect_up_stream_protocol(h2_stream_info, NULL, 0, data[len], datalen[len]);
}
}
+
+ sess_data_ctx_fini(tapinfo->h2_stream_info, NULL, 0);
+ free(tapinfo->h2_stream_info);
+ free(tapinfo);
}
TEST(UI_TEST_INFLATE_GZIP, inflate_01)
{
char *uncompr = NULL;
- struct tfe_h2_payload body;
int ret = 0, uncompr_len = 0;
-
- memset(&body, 0, sizeof(struct tfe_h2_payload));
-
- ret = inflate_read(ut_gip_01, sizeof(ut_gip_01), &uncompr, &uncompr_len, &(body.inflate), 2);
+ struct z_stream_st *inflate = NULL;
+ ret = inflate_read(ut_gip_01, sizeof(ut_gip_01), &uncompr, &uncompr_len, &inflate, 2);
EXPECT_EQ(ret, Z_STREAM_END);
EXPECT_EQ(uncompr_len, sizeof(ut_ungip_01));
EXPECT_EQ(memcmp(uncompr, ut_ungip_01, sizeof(ut_ungip_01)), 0);
+ inflate_finished(&inflate);
- free(uncompr);
+ free(uncompr);
uncompr = NULL;
}
TEST(UI_TEST_INFLATE_GZIP, inflate_02)
{
- struct tfe_h2_payload body;
- int ret = 0, half = 0;
- int size = sizeof(ut_gip_01);
+ struct z_stream_st *inflate = NULL;
+ int ret = 0, half = 0;
+ int size = sizeof(ut_gip_01);
half = size / 2;
- body.inflate = NULL;
-
char *uncompr1 = NULL; int uncompr_len1 = 0;
- ret = inflate_read(ut_gip_01, half, &uncompr1, &uncompr_len1, &(body.inflate), 2);
+ ret = inflate_read(ut_gip_01, half, &uncompr1, &uncompr_len1, &inflate, 2);
EXPECT_EQ(ret, Z_OK);
char *uncompr2 = NULL; int uncompr_len2 = 0;
- ret = inflate_read(ut_gip_01 + half, size - half, &uncompr2, &uncompr_len2, &(body.inflate), 2);
+ ret = inflate_read(ut_gip_01 + half, size - half, &uncompr2, &uncompr_len2, &inflate, 2);
EXPECT_EQ(ret, Z_STREAM_END);
- char uncompr[1024] = {0};
- snprintf(uncompr, 1024 -1, "%s%s", uncompr1, uncompr2);
+ char uncompr[1024] = {0};
+ memcpy(uncompr, uncompr1, uncompr_len1);
+ memcpy(uncompr + uncompr_len1, uncompr2, uncompr_len2);
EXPECT_EQ(uncompr_len1 + uncompr_len2, sizeof(ut_ungip_01));
- //EXPECT_EQ(memcmp(uncompr, ut_ungip_01, sizeof(ut_ungip_01)), 0);
+ EXPECT_EQ(memcmp(uncompr, ut_ungip_01, sizeof(ut_ungip_01)), 0);
- free(uncompr1);
+ inflate_finished(&inflate);
+ free(uncompr1);
uncompr1 = NULL;
free(uncompr2);
uncompr2 = NULL;
@@ -361,34 +380,34 @@ TEST(UI_TEST_INFLATE_GZIP, inflate_02)
TEST(UI_TEST_DEFLATE_GZIP, deflate_01)
{
unsigned char *dest = NULL;
- struct tfe_h2_payload body;
int ret = 0, dlen = 0;
struct evbuffer * buf = evbuffer_new();
int size = sizeof(ut_ungip_01);
- memset(&body, 0, sizeof(struct tfe_h2_payload));
-
- ret = deflate_write(&(body.deflate), ut_ungip_01, size, buf, 2, 1);
+ struct z_stream_st *deflate = NULL;
+ ret = deflate_write(&deflate, ut_ungip_01, size, buf, 2, 1);
EXPECT_EQ(ret, Z_OK);
+ deflate_finished(&deflate);
- dest = evbuffer_pullup(buf, -1);
+ dest = evbuffer_pullup(buf, -1);
dlen = evbuffer_get_length(buf);
char *uncompr = NULL;
int uncompr_len = 0;
- ret = inflate_read(dest, dlen, &uncompr, &uncompr_len, &(body.inflate), 2);
- EXPECT_EQ(ret, Z_STREAM_END);
+ struct z_stream_st *inflate = NULL;
+ ret = inflate_read(dest, dlen, &uncompr, &uncompr_len, &inflate, 2);
+ EXPECT_EQ(ret, Z_STREAM_END);
EXPECT_EQ(uncompr_len, sizeof(ut_ungip_01));
EXPECT_EQ(memcmp(uncompr, ut_ungip_01, sizeof(ut_ungip_01)), 0);
- free(uncompr);
+ inflate_finished(&inflate);
+ free(uncompr);
uncompr = NULL;
evbuffer_free(buf);
}
TEST(UI_TEST_DEFLATE_GZIP, deflate_02)
{
- struct tfe_h2_payload body;
unsigned char *dest = NULL;
int ret = 0, half = 0, dlen = 0;
@@ -396,32 +415,33 @@ TEST(UI_TEST_DEFLATE_GZIP, deflate_02)
half = size / 2;
struct evbuffer * buf = evbuffer_new();
-
- memset(&body, 0, sizeof(struct tfe_h2_payload));
-
- /* First frag */
- ret = deflate_write(&(body.deflate), ut_ungip_01, half, buf, 2, 0);
+ struct z_stream_st *deflate = NULL;
+ /* First frag */
+ ret = deflate_write(&deflate, ut_ungip_01, half, buf, 2, 0);
EXPECT_EQ(ret, Z_OK);
/* Last frag */
- ret = deflate_write(&(body.deflate), ut_ungip_01 + half, size - half, buf, 2, 0);
+ ret = deflate_write(&deflate, ut_ungip_01 + half, size - half, buf, 2, 0);
EXPECT_EQ(ret, Z_OK);
/* End frag */
- ret = deflate_write(&(body.deflate), NULL, 0, buf, 2, 1);
+ ret = deflate_write(&deflate, NULL, 0, buf, 2, 1);
EXPECT_EQ(ret, Z_OK);
+ deflate_finished(&deflate);
- dest = evbuffer_pullup(buf, -1);
+ dest = evbuffer_pullup(buf, -1);
dlen = evbuffer_get_length(buf);
char *uncompr = NULL;
int uncompr_len = 0;
- ret = inflate_read(dest, dlen, &uncompr, &uncompr_len, &(body.inflate), 2);
+ struct z_stream_st *inflate = NULL;
+ ret = inflate_read(dest, dlen, &uncompr, &uncompr_len, &inflate, 2);
EXPECT_EQ(ret, Z_STREAM_END);
EXPECT_EQ(uncompr_len, sizeof(ut_ungip_01));
EXPECT_EQ(memcmp(uncompr, ut_ungip_01, sizeof(ut_ungip_01)), 0);
+ inflate_finished(&inflate);
- free(uncompr);
+ free(uncompr);
uncompr = NULL;
evbuffer_free(buf);
}
@@ -429,34 +449,34 @@ TEST(UI_TEST_DEFLATE_GZIP, deflate_02)
TEST(UI_TEST_DEFLATE_BR, deflate_01)
{
unsigned char *dest = NULL;
- struct tfe_h2_payload body;
int ret = 0, dlen = 0;
struct evbuffer * buf = evbuffer_new();
int size = sizeof(ut_ungip_01);
- memset(&body, 0, sizeof(struct tfe_h2_payload));
-
- ret = deflate_write(&(body.deflate), ut_ungip_01, size, buf, HTTP2_CONTENT_ENCODING_BR, 1);
+ struct z_stream_st *deflate = NULL;
+ ret = deflate_write(&deflate, ut_ungip_01, size, buf, HTTP2_CONTENT_ENCODING_BR, 1);
EXPECT_EQ(ret, Z_OK);
+ deflate_finished(&deflate);
- dest = evbuffer_pullup(buf, -1);
+ dest = evbuffer_pullup(buf, -1);
dlen = evbuffer_get_length(buf);
char *uncompr = NULL;
int uncompr_len = 0;
- ret = inflate_read(dest, dlen, &uncompr, &uncompr_len, &(body.inflate), HTTP2_CONTENT_ENCODING_BR);
+ struct z_stream_st *inflate = NULL;
+ ret = inflate_read(dest, dlen, &uncompr, &uncompr_len, &inflate, HTTP2_CONTENT_ENCODING_BR);
EXPECT_EQ(ret, Z_STREAM_END);
EXPECT_EQ(uncompr_len, sizeof(ut_ungip_01));
EXPECT_EQ(memcmp(uncompr, ut_ungip_01, sizeof(ut_ungip_01)), 0);
+ inflate_finished(&inflate);
- free(uncompr);
+ free(uncompr);
uncompr = NULL;
evbuffer_free(buf);
}
TEST(UI_TEST_DEFLATE_BR, deflate_02)
{
- struct tfe_h2_payload body;
unsigned char *dest = NULL;
int ret = 0, half = 0, dlen = 0;
@@ -464,32 +484,33 @@ TEST(UI_TEST_DEFLATE_BR, deflate_02)
half = size / 2;
struct evbuffer * buf = evbuffer_new();
-
- memset(&body, 0, sizeof(struct tfe_h2_payload));
-
- /* First frag */
- ret = deflate_write(&(body.deflate), ut_ungip_01, half, buf, HTTP2_CONTENT_ENCODING_BR, 0);
+ struct z_stream_st *deflate = NULL;
+ /* First frag */
+ ret = deflate_write(&deflate, ut_ungip_01, half, buf, HTTP2_CONTENT_ENCODING_BR, 0);
EXPECT_EQ(ret, Z_OK);
/* Last frag */
- ret = deflate_write(&(body.deflate), ut_ungip_01 + half, size - half, buf, HTTP2_CONTENT_ENCODING_BR, 0);
+ ret = deflate_write(&deflate, ut_ungip_01 + half, size - half, buf, HTTP2_CONTENT_ENCODING_BR, 0);
EXPECT_EQ(ret, Z_OK);
/* End frag */
- ret = deflate_write(&(body.deflate), NULL, 0, buf, HTTP2_CONTENT_ENCODING_BR, 1);
+ ret = deflate_write(&deflate, NULL, 0, buf, HTTP2_CONTENT_ENCODING_BR, 1);
EXPECT_EQ(ret, Z_OK);
+ deflate_finished(&deflate);
- dest = evbuffer_pullup(buf, -1);
+ dest = evbuffer_pullup(buf, -1);
dlen = evbuffer_get_length(buf);
char *uncompr = NULL;
int uncompr_len = 0;
- ret = inflate_read(dest, dlen, &uncompr, &uncompr_len, &(body.inflate), HTTP2_CONTENT_ENCODING_BR);
+ struct z_stream_st *inflate = NULL;
+ ret = inflate_read(dest, dlen, &uncompr, &uncompr_len, &inflate, HTTP2_CONTENT_ENCODING_BR);
EXPECT_EQ(ret, Z_STREAM_END);
EXPECT_EQ(uncompr_len, sizeof(ut_ungip_01));
EXPECT_EQ(memcmp(uncompr, ut_ungip_01, sizeof(ut_ungip_01)), 0);
+ inflate_finished(&inflate);
- free(uncompr);
+ free(uncompr);
uncompr = NULL;
evbuffer_free(buf);
}