增加HTTP解析层的REQ_END, RESP_END类型回调事件,增加HTTP POST类型的单元测试用例。

This commit is contained in:
Lu Qiuwen
2018-09-20 11:37:12 +08:00
parent 08779fb8e1
commit bb27166df0
3 changed files with 390 additions and 12 deletions

View File

@@ -268,7 +268,7 @@ static int __parser_callback_on_body(struct http_parser * parser, const char * a
hf_private->event_cb(hf_private, ev_body_begin, NULL, parser->content_length, hf_private->event_cb_user);
}
if (hf_private->event_cb)
if (hf_private->event_cb && length != 0)
{
hf_private->event_cb(hf_private, ev_body_cont, (const unsigned char *) at, length, hf_private->event_cb_user);
}
@@ -281,20 +281,29 @@ static int __parser_callback_on_message_complete(http_parser * parser)
{
struct http_half_private * hf_private = __PARSER_TO_HF_PRIVATE(parser);
enum tfe_http_direction hf_direction = hf_private->hf_public.direction;
enum tfe_http_event ev_message_end;
enum tfe_http_event ev_body_end;
if (hf_direction == TFE_HTTP_REQUEST)
{
ev_message_end = EV_HTTP_REQ_END;
ev_body_end = EV_HTTP_REQ_BODY_END;
}
else
{
ev_message_end = EV_HTTP_RESP_END;
ev_body_end = EV_HTTP_RESP_BODY_END;
}
if (hf_private->event_cb && hf_private->body_status == STATUS_READING)
{
hf_private->event_cb(hf_private, ev_body_end, NULL, 0, hf_private->event_cb_user);
}
if (hf_private->event_cb)
{
hf_private->event_cb(hf_private, ev_body_end, NULL, 0, hf_private->event_cb_user);
hf_private->event_cb(hf_private, ev_message_end, NULL, 0, hf_private->event_cb_user);
}
hf_private->body_status = STATUS_COMPLETE;