修正suspend/resume语义实现的若干问题,增加自行构建request/response的header标志
This commit is contained in:
@@ -348,7 +348,7 @@ static int __parser_callback_on_headers_complete(http_parser * parser)
|
||||
|
||||
/* user's suspend tag is set, which indicate that the way to handle request/response
|
||||
* cannot be determinate at now, need to defer */
|
||||
else if (hs_private && hs_private->suspend_tag_user)
|
||||
else if (hs_private && hs_private->suspend_tag_effective)
|
||||
{
|
||||
/* Pause parser, prevent to parse request/response body,
|
||||
* The body should be parsed after resume() */
|
||||
@@ -362,7 +362,7 @@ static int __parser_callback_on_headers_complete(http_parser * parser)
|
||||
assert(hf_private->stream_action == ACTION_DEFER_DATA);
|
||||
}
|
||||
|
||||
/* Otherwise, forward the request/response */
|
||||
/* Otherwise, forward the request/response */
|
||||
else
|
||||
{
|
||||
hf_private->stream_action = ACTION_FORWARD_DATA;
|
||||
@@ -615,9 +615,8 @@ int hf_ops_body_begin(struct tfe_http_half * half, int by_stream)
|
||||
}
|
||||
|
||||
hf_private->content_encoding = HTTP_ACCEPT_ENCODING_NONE;
|
||||
hf_private->message_status = STATUS_READING;
|
||||
hf_private->is_setup_by_stream = true;
|
||||
|
||||
hs_private->stream_write_tag_effective = true;
|
||||
hs_private->release_lock++;
|
||||
}
|
||||
|
||||
@@ -679,8 +678,7 @@ int hf_ops_body_end(struct tfe_http_half * half)
|
||||
|
||||
if(hf_private->is_setup_by_stream)
|
||||
{
|
||||
hs_private->stream_write_tag_effective = true;
|
||||
hs_private->release_lock++;
|
||||
hs_private->release_lock--;
|
||||
}
|
||||
|
||||
printf("frag write end, stream = %p, hf_private = %p\n", hf_private->session->hc_private->stream, hf_private);
|
||||
@@ -802,7 +800,7 @@ int hf_private_parse(struct http_half_private * hf_private, const unsigned char
|
||||
* resume it to normal status */
|
||||
if (__is_paused)
|
||||
{
|
||||
hf_private->parse_cursor += sz_parsed + 1;
|
||||
hf_private->parse_cursor += sz_parsed;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -829,8 +827,15 @@ void hs_ops_drop(struct tfe_http_session * session)
|
||||
void hs_ops_suspend(struct tfe_http_session * session)
|
||||
{
|
||||
struct http_session_private * hs_private = to_hs_private(session);
|
||||
hs_private->suspend_tag_user = true;
|
||||
struct http_connection_private * hc_private = hs_private->hc_private;
|
||||
|
||||
hs_private->release_lock++;
|
||||
hs_private->suspend_counter++;
|
||||
hs_private->suspend_tag_effective = true;
|
||||
|
||||
tfe_stream_suspend(hc_private->stream, CONN_DIR_DOWNSTREAM);
|
||||
fprintf(stderr, "---- suspend ----, url = %s, counter = %d\n",
|
||||
hs_private->hs_public.req->req_spec.url, hs_private->suspend_counter);
|
||||
}
|
||||
|
||||
void hs_ops_resume(struct tfe_http_session * session)
|
||||
@@ -838,9 +843,16 @@ void hs_ops_resume(struct tfe_http_session * session)
|
||||
struct http_session_private * hs_private = to_hs_private(session);
|
||||
struct http_connection_private * hc_private = hs_private->hc_private;
|
||||
|
||||
hs_private->suspend_tag_user = false;
|
||||
assert(!hs_private->in_gc_queue);
|
||||
|
||||
hs_private->release_lock--;
|
||||
tfe_stream_resume(hc_private->stream);
|
||||
if (hs_private->suspend_tag_effective)
|
||||
{
|
||||
tfe_stream_resume(hc_private->stream);
|
||||
}
|
||||
|
||||
fprintf(stderr, "---- resume ----, url = %s, counter = %d\n",
|
||||
hs_private->hs_public.req->req_spec.url, hs_private->suspend_counter);
|
||||
}
|
||||
|
||||
// TODO: change the return type to int, there is something happend where -1 returned.
|
||||
@@ -865,6 +877,8 @@ void hs_ops_request_set(struct tfe_http_session * session, struct tfe_http_half
|
||||
|
||||
assert(hs_private->hf_private_req_user == NULL);
|
||||
hs_private->hf_private_req_user = hf_user_private;
|
||||
hs_private->hf_private_req_user->message_status = STATUS_COMPLETE;
|
||||
hs_private->hf_private_req_user->session = hs_private;
|
||||
}
|
||||
|
||||
void hs_ops_response_set(struct tfe_http_session * session, struct tfe_http_half * resp)
|
||||
@@ -897,7 +911,8 @@ void hs_ops_response_set(struct tfe_http_session * session, struct tfe_http_half
|
||||
|
||||
assert(hs_private->hf_private_resp_user == NULL);
|
||||
hs_private->hf_private_resp_user = hf_private;
|
||||
hf_private->session = hs_private;
|
||||
hs_private->hf_private_resp_user->message_status = STATUS_COMPLETE;
|
||||
hs_private->hf_private_resp_user->session = hs_private;
|
||||
}
|
||||
|
||||
struct tfe_http_half * hs_ops_request_create(struct tfe_http_session * session,
|
||||
@@ -1042,6 +1057,8 @@ void hf_private_construct(struct http_half_private * hf_private)
|
||||
evbuffer_add_printf(hf_private->evbuf_raw, "%s: %s\r\n", str_field, str_value);
|
||||
}
|
||||
|
||||
/* Trace Tags */
|
||||
evbuffer_add_printf(hf_private->evbuf_raw, "%s: tfe/%s\r\n", "X-TG-Construct-By", tfe_version());
|
||||
/* delimitor between header and body */
|
||||
evbuffer_add_printf(hf_private->evbuf_raw, "\r\n");
|
||||
|
||||
@@ -1154,8 +1171,20 @@ void hs_private_destroy(struct http_session_private * hs_private)
|
||||
|
||||
void hs_private_gc_destroy(struct http_session_private * hs_private, struct hs_private_list * gc_list)
|
||||
{
|
||||
if (hs_private->release_lock > 0) TAILQ_INSERT_TAIL(gc_list, hs_private, next);
|
||||
else return hs_private_destroy(hs_private);
|
||||
if (hs_private->release_lock > 0)
|
||||
{
|
||||
TAILQ_INSERT_TAIL(gc_list, hs_private, next);
|
||||
hs_private->in_gc_queue = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return hs_private_destroy(hs_private);
|
||||
}
|
||||
}
|
||||
|
||||
bool hs_private_can_destroy(struct http_session_private * hs_private)
|
||||
{
|
||||
return hs_private->release_lock <= 0;
|
||||
}
|
||||
|
||||
void hs_private_hf_private_set(struct http_session_private * hs_private,
|
||||
|
||||
Reference in New Issue
Block a user