在HttpParser中集成解压缩模块并编写对应的单元测试用例。
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#include <tfe_http.h>
|
||||
#include <tfe_utils.h>
|
||||
#include <http_half.h>
|
||||
#include <http_convert.h>
|
||||
|
||||
#define __PARSER_TO_HF_PRIVATE(_parser) ((struct http_half_private *)(_parser->data))
|
||||
|
||||
@@ -88,7 +89,7 @@ uint16_t __hf_content_encoding_parse(const char * str_content_encoding)
|
||||
return HTTP_ACCEPT_ENCODING_X_BZIP2;
|
||||
}
|
||||
|
||||
return HTTP_ACCEPT_ENCODING_IDENTITY;
|
||||
return HTTP_ACCEPT_ENCODING_NONE;
|
||||
}
|
||||
|
||||
/* To flush header field and value which stash in evbuffer */
|
||||
@@ -328,15 +329,40 @@ static int __parser_callback_on_body(struct http_parser * parser, const char * a
|
||||
|
||||
if (hf_private->body_status == STATUS_INIT && hf_private->event_cb)
|
||||
{
|
||||
/* Create ungzip context */
|
||||
if (hf_private->content_encoding != HTTP_ACCEPT_ENCODING_NONE)
|
||||
{
|
||||
hf_private->cv_unpress_object = hf_content_converter_create(HF_CONTENT_CONV_UNCOMPRASS,
|
||||
hf_private->content_encoding, hf_private->event_cb, hf_private->event_cb_user);
|
||||
|
||||
if (unlikely(hf_private->cv_unpress_object == NULL)) assert(0);
|
||||
}
|
||||
|
||||
hf_private->event_cb(hf_private, ev_body_begin, NULL, parser->content_length, hf_private->event_cb_user);
|
||||
hf_private->body_status = STATUS_READING;
|
||||
}
|
||||
|
||||
int ret = 0;
|
||||
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);
|
||||
if (hf_private->cv_unpress_object != NULL)
|
||||
{
|
||||
ret = hf_content_converter_write(hf_private->cv_unpress_object, hf_private, ev_body_cont,
|
||||
(const unsigned char *)at, length);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = hf_private->event_cb(hf_private, ev_body_cont, (const unsigned char *) at,
|
||||
length, hf_private->event_cb_user);
|
||||
}
|
||||
|
||||
if (ret < 0)
|
||||
{
|
||||
//TODO: what to do if writter raise an error.
|
||||
assert(0);
|
||||
}
|
||||
}
|
||||
|
||||
hf_private->body_status = STATUS_READING;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -557,7 +583,7 @@ int hf_private_parse(struct http_half_private * hf_private, const unsigned char
|
||||
&__http_half_parse_setting, __data_with_offset, __len_with_offset);
|
||||
|
||||
/* Nothing happended */
|
||||
if (sz_parsed == len)
|
||||
if (sz_parsed == __len_with_offset)
|
||||
{
|
||||
hf_private->parse_cursor += sz_parsed;
|
||||
return HTTP_PARSER_ERRNO(hf_private->parse_object) == HPE_PAUSED ? 1 : 0;
|
||||
@@ -573,6 +599,7 @@ int hf_private_parse(struct http_half_private * hf_private, const unsigned char
|
||||
}
|
||||
|
||||
hf_private->parse_errno = HTTP_PARSER_ERRNO(hf_private->parse_object);
|
||||
assert(hf_private->parse_errno != HPE_OK);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user