增加对GZIP压缩编码的解压缩功能及单元测试用例
This commit is contained in:
@@ -61,6 +61,36 @@ static enum tfe_http_std_field __str_header_field_to_std_field_id(const char * s
|
||||
return TFE_HTTP_UNKNOWN_FIELD;
|
||||
}
|
||||
|
||||
uint16_t __hf_content_encoding_parse(const char * str_content_encoding)
|
||||
{
|
||||
if (strcasestr(str_content_encoding, "gzip") != NULL)
|
||||
{
|
||||
return HTTP_ACCEPT_ENCODING_GZIP;
|
||||
}
|
||||
|
||||
if (strcasestr(str_content_encoding, "x-gzip") != NULL)
|
||||
{
|
||||
return HTTP_ACCEPT_ENCODING_X_GZIP;
|
||||
}
|
||||
|
||||
if (strcasestr(str_content_encoding, "deflate") != NULL)
|
||||
{
|
||||
return HTTP_ACCEPT_ENCODING_DEFLATE;
|
||||
}
|
||||
|
||||
if (strcasestr(str_content_encoding, "bzip2") != NULL)
|
||||
{
|
||||
return HTTP_ACCEPT_ENCODING_BZIP2;
|
||||
}
|
||||
|
||||
if (strcasestr(str_content_encoding, "x-bzip2") != NULL)
|
||||
{
|
||||
return HTTP_ACCEPT_ENCODING_X_BZIP2;
|
||||
}
|
||||
|
||||
return HTTP_ACCEPT_ENCODING_IDENTITY;
|
||||
}
|
||||
|
||||
/* To flush header field and value which stash in evbuffer */
|
||||
static void __http_half_header_kv_complete(struct http_half_private * hf_private)
|
||||
{
|
||||
@@ -120,12 +150,7 @@ void __hf_public_req_fill_from_private(struct http_half_private * hf_private, st
|
||||
|
||||
/* accept-encoding, host is located in header's K-V structure */
|
||||
hf_req_spec->method = (enum tfe_http_std_method) parser->method;
|
||||
const static struct http_field_name __host_field_name =
|
||||
{
|
||||
.field_id = TFE_HTTP_HOST,
|
||||
.field_name = NULL
|
||||
};
|
||||
|
||||
const static struct http_field_name __host_field_name = {TFE_HTTP_HOST, NULL};
|
||||
hf_req_spec->host = (char *) tfe_http_field_read(hf_public, &__host_field_name);
|
||||
|
||||
/* uri is stored in underlay evbuffer, we need to append a terminal zero */
|
||||
@@ -157,31 +182,25 @@ void __hf_public_resp_fill_from_private(struct http_half_private * hf_private, s
|
||||
hf_resp_spec->resp_code = parser->status_code;
|
||||
|
||||
/* Content Type */
|
||||
const static struct http_field_name __cont_encoding_type_name =
|
||||
{
|
||||
.field_id = TFE_HTTP_CONT_TYPE,
|
||||
.field_name = NULL
|
||||
};
|
||||
|
||||
const static struct http_field_name __cont_encoding_type_name = {TFE_HTTP_CONT_TYPE, NULL};
|
||||
hf_resp_spec->content_type = (char *) tfe_http_field_read(hf_public, &__cont_encoding_type_name);
|
||||
|
||||
/* Content Length */
|
||||
const static struct http_field_name __cont_encoding_length_name =
|
||||
{
|
||||
.field_id = TFE_HTTP_CONT_LENGTH,
|
||||
.field_name = NULL
|
||||
};
|
||||
|
||||
const static struct http_field_name __cont_encoding_length_name = {TFE_HTTP_CONT_LENGTH, NULL};
|
||||
hf_resp_spec->content_length = (char *) tfe_http_field_read(hf_public, &__cont_encoding_length_name);
|
||||
|
||||
/* Content Encoding */
|
||||
const static struct http_field_name __cont_encoding_field_name =
|
||||
{
|
||||
.field_id = TFE_HTTP_CONT_ENCODING,
|
||||
.field_name = NULL
|
||||
};
|
||||
|
||||
const static struct http_field_name __cont_encoding_field_name = {TFE_HTTP_CONT_ENCODING, NULL};
|
||||
hf_resp_spec->content_encoding = (char *) tfe_http_field_read(hf_public, &__cont_encoding_field_name);
|
||||
|
||||
if (hf_resp_spec->content_encoding != NULL)
|
||||
{
|
||||
hf_private->content_encoding = __hf_content_encoding_parse(hf_resp_spec->content_encoding);
|
||||
}
|
||||
else
|
||||
{
|
||||
hf_private->content_encoding = HTTP_ACCEPT_ENCODING_IDENTITY;
|
||||
}
|
||||
}
|
||||
|
||||
/* ==================================================================================================================
|
||||
@@ -656,7 +675,7 @@ struct tfe_http_session_ops __http_session_ops =
|
||||
|
||||
void __construct_request_line(struct http_half_private * hf_private)
|
||||
{
|
||||
enum tfe_http_std_method __std_method = (enum tfe_http_std_method ) hf_private->method_or_status;
|
||||
enum tfe_http_std_method __std_method = (enum tfe_http_std_method) hf_private->method_or_status;
|
||||
const char * __str_method = http_std_method_to_string(__std_method);
|
||||
if (__str_method == NULL)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user