增加Per Stream摘要日志功能,修正TCP上、下游连接不能联动关闭的问题。
* 增加Per Stream摘要日志功能,记录连接四元组、HTTP URL等关键信息,便于调试; * 原实现在上游连接关闭时,不能关闭下游连接(反之亦然),现修正。
This commit is contained in:
@@ -28,6 +28,7 @@ int http_connection_entry_open(const struct tfe_stream * stream, unsigned int th
|
||||
{
|
||||
struct http_connection_private * ht_conn = ALLOC(struct http_connection_private, 1);
|
||||
TAILQ_INIT(&ht_conn->hs_private_list);
|
||||
ht_conn->stream = stream;
|
||||
*pme = (void *)ht_conn;
|
||||
return 0;
|
||||
}
|
||||
@@ -89,12 +90,18 @@ enum tfe_stream_action __http_connection_entry_on_request(const struct tfe_strea
|
||||
TAILQ_INSERT_TAIL(&hc_private->hs_private_list, hs_private, next);
|
||||
}
|
||||
|
||||
/* proceed parse content for last request */
|
||||
/* Parse the content, the data which in defered state has been ignored. */
|
||||
ret = hf_private_parse(hf_private_request, data, len);
|
||||
|
||||
/* Need more data, no boundary touched */
|
||||
if (ret == 0)
|
||||
{
|
||||
if (hf_private_request->stream_action == ACTION_DROP_DATA ||
|
||||
hf_private_request->stream_action == ACTION_FORWARD_DATA)
|
||||
{
|
||||
hf_private_request->parse_cursor = 0;
|
||||
}
|
||||
|
||||
return hf_private_request->stream_action;
|
||||
}
|
||||
|
||||
@@ -185,8 +192,19 @@ __detach:
|
||||
void http_connection_entry_close(const struct tfe_stream * stream, unsigned int thread_id,
|
||||
enum tfe_stream_close_reason reason, void ** pme)
|
||||
{
|
||||
struct http_connection_private * __ht_conn = (struct http_connection_private *)(*pme);
|
||||
free(__ht_conn);
|
||||
struct http_connection_private * ht_conn = (struct http_connection_private *)(*pme);
|
||||
|
||||
/* Delete all live sessions */
|
||||
struct http_session_private * hs_private_iter = NULL;
|
||||
TAILQ_FOREACH(hs_private_iter, &ht_conn->hs_private_list, next)
|
||||
{
|
||||
TAILQ_REMOVE(&ht_conn->hs_private_list, hs_private_iter, next);
|
||||
hs_private_destory(hs_private_iter);
|
||||
}
|
||||
|
||||
/* Clear session counter, and free ht_conn structure */
|
||||
ht_conn->session_id_counter = 0;
|
||||
free(ht_conn); *pme = NULL;
|
||||
}
|
||||
|
||||
static struct tfe_plugin __http_plugin_info =
|
||||
|
||||
@@ -560,7 +560,36 @@ struct http_session_private * hs_private_create(struct http_connection_private *
|
||||
return __hs_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);
|
||||
/* Req-Public */
|
||||
struct tfe_http_req_spec * req_spec = request ? &to_hf_public(request)->req_spec : NULL;
|
||||
/* Resp-Public */
|
||||
struct tfe_http_resp_spec * resp_spec = response ? &to_hf_public(response)->resp_spec : NULL;
|
||||
|
||||
/* 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);
|
||||
|
||||
const struct tfe_stream * stream = hs_private->hc_private->stream;
|
||||
tfe_stream_write_log(stream, RLOG_LV_INFO, "%s", __access_log);
|
||||
(void)resp_spec;
|
||||
}
|
||||
|
||||
void hs_private_destory(struct http_session_private * hs_private)
|
||||
{
|
||||
__write_access_log(hs_private);
|
||||
free(hs_private);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user