修正HTTP Early Answer功能在HTTP头部带有Body时的引发assert的问题。

* 原实现无法正确处理HTTP请求带有Body时,业务层执行Early Answer动作;
* 现修正为HTTP请求头完整时,检查是否需要Early-Answer。如果请求已经向真实服务器转发,则不执行Early-Answer动作。
This commit is contained in:
Lu Qiuwen
2018-10-25 10:54:53 +08:00
parent 09cac7256b
commit 2cea50f48c
2 changed files with 18 additions and 12 deletions

View File

@@ -198,6 +198,12 @@ int __on_request_handle_user_req_or_resp(const tfe_stream * stream, struct http_
/* Cannot setup user request and user response simultaneously */
assert(!(hs_private->hf_private_req_user != NULL && hs_private->hf_private_resp_user != NULL));
/* Only construct HTTP request or early answer response when incoming request is complete */
if (hf_private_req_in->message_status != STATUS_COMPLETE)
{
return 0;
}
/* User's construct request */
if (hs_private->hf_private_req_user != NULL)
{
@@ -215,17 +221,23 @@ int __on_request_handle_user_req_or_resp(const tfe_stream * stream, struct http_
hs_private->hf_private_req_user = NULL;
}
assert(hf_private_req_in->stream_action == ACTION_DEFER_DATA
|| hf_private_req_in->stream_action == ACTION_DROP_DATA);
hf_private_req_in->stream_action = ACTION_DROP_DATA;
if (hf_private_req_in->stream_action == ACTION_DROP_DATA ||
hf_private_req_in->stream_action == ACTION_DEFER_DATA)
{
hf_private_req_in->stream_action = ACTION_DROP_DATA;
}
}
/* User's construct response, send before real response arrived. */
else if (hs_private->hf_private_resp_user != NULL)
/* User's construct response, send before real response arrive.
* Only early answer while the incoming request is send.
* Otherwise, we will construct user's response when real response arrived. */
if (hs_private->hf_private_resp_user != NULL /* User response setup */
&& hf_private_req_in->stream_action == ACTION_DROP_DATA /* Incoming request does not sent */)
{
struct http_half_private * hf_private_resp_user = hs_private->hf_private_resp_user;
ret = __write_http_half_to_line(stream, CONN_DIR_DOWNSTREAM, hf_private_resp_user);
if (unlikely(ret < 0))
{
TFE_STREAM_LOG_ERROR(stream, "Failed to write HTTP request setup by user".);
@@ -243,10 +255,6 @@ int __on_request_handle_user_req_or_resp(const tfe_stream * stream, struct http_
TAILQ_REMOVE(&hc_private->hs_private_list, hs_private, next);
TAILQ_INSERT_TAIL(&hc_private->hs_private_orphan_list, hs_private, next);
}
assert(hf_private_req_in->stream_action == ACTION_DEFER_DATA
|| hf_private_req_in->stream_action == ACTION_DROP_DATA);
hf_private_req_in->stream_action = ACTION_DROP_DATA;
}
return 0;