初步完成HTTP应答侧解析功能,并修正一系类错误处理类的问题。

This commit is contained in:
Lu Qiuwen
2018-09-23 17:33:05 +08:00
parent 7b6dbb06aa
commit 2798783641
10 changed files with 223 additions and 49 deletions

View File

@@ -145,13 +145,32 @@ void __hf_public_resp_fill_from_private(struct http_half_private * hf_private, s
/* Status Code */
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
};
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
};
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
};
/* Content Encoding */
hf_resp_spec->content_encoding = (char *) tfe_http_field_read(hf_public, &__cont_encoding_field_name);
}
@@ -563,13 +582,11 @@ struct http_session_private * hs_private_create(struct http_connection_private *
void __write_access_log(struct http_session_private * hs_private)
{
/* Prepare to write session access log */
char __access_log[TFE_STRING_MAX];
size_t __offset = 0;
/* Request */
struct http_half_private * request = to_hf_request_private(hs_private);
/* Response */
struct http_half_private * response = to_hf_request_private(hs_private);
struct http_half_private * response = to_hf_response_private(hs_private);
/* Req-Public */
struct tfe_http_req_spec * req_spec = request ? &to_hf_public(request)->req_spec : NULL;
/* Resp-Public */
@@ -577,15 +594,34 @@ void __write_access_log(struct http_session_private * hs_private)
/* Method */
const char * __str_method = req_spec ? http_std_method_to_string(req_spec->method) : "-";
__offset += snprintf(__access_log + __offset, sizeof(__access_log) - __offset, "%s ", __str_method);
/* URL */
const char * __str_url = req_spec ? req_spec->url : "-";
__offset += snprintf(__access_log + __offset, sizeof(__access_log) - __offset, "%s ", __str_url);
/* Resp code */
char __str_resp_code[TFE_STRING_MAX];
if (resp_spec)
{
snprintf(__str_resp_code, sizeof(__str_resp_code) - 1, "%d", resp_spec->resp_code);
}
else
{
snprintf(__str_resp_code, sizeof(__str_resp_code) - 1, "%s", "-");
}
/* Content Type */
const char * __str_cont_type = resp_spec ? resp_spec->content_type : "-";
/* Content Length */
const char * __str_cont_length = resp_spec ? resp_spec->content_length : "-";
/* Content Encoding */
const char * __str_cont_encoding = resp_spec ? resp_spec->content_encoding : "-";
char * __access_log;
asprintf(&__access_log, "%s %s %s %s %s %s", __str_method,
__str_url, __str_resp_code, __str_cont_type, __str_cont_length, __str_cont_encoding);
const struct tfe_stream * stream = hs_private->hc_private->stream;
tfe_stream_write_access_log(stream, RLOG_LV_INFO, "%s", __access_log);
(void)resp_spec;
free(__access_log);
}
void hs_private_destory(struct http_session_private * hs_private)
@@ -593,3 +629,39 @@ void hs_private_destory(struct http_session_private * hs_private)
__write_access_log(hs_private);
free(hs_private);
}
void hs_private_hf_private_set(struct http_session_private * hs_private, struct http_half_private * hf,
enum tfe_http_direction direction)
{
struct tfe_http_half ** ref_old_half_public;
struct http_half_private * old_half_private;
if (direction == TFE_HTTP_REQUEST)
{
ref_old_half_public = &hs_private->hs_public.req;
old_half_private = to_hf_private(*ref_old_half_public);
}
else
{
ref_old_half_public = &hs_private->hs_public.resp;
old_half_private = to_hf_private(*ref_old_half_public);
}
if (old_half_private != NULL)
{
hf_private_destory(old_half_private);
*ref_old_half_public = to_hf_public(hf);
}
else
{
*ref_old_half_public = to_hf_public(hf);
}
return;
}
struct http_half_private * hs_private_hf_private_release(struct http_session_private * hs_private,
enum tfe_http_direction)
{
return nullptr;
}