*删除nghttp2中收到ping ack字符会ping
*由于命中匹配规则且返回数据中只有 header,造成数据丢失,在当前流close时添加header注册接口
This commit is contained in:
@@ -34,6 +34,7 @@ typedef enum {
|
||||
NGHTTP2_METHOD_POST = 3,
|
||||
NGHTTP2_METHOD_PUT = 4,
|
||||
NGHTTP2_METHOD_CONNECT = 5,
|
||||
NGHTTP2_METHOD_OPTIONS = 6,
|
||||
NGHTTP2_METHOD_UNKNOWN,
|
||||
}nghttp2_method;
|
||||
|
||||
|
||||
@@ -80,7 +80,6 @@ struct h2_stream_data_t{
|
||||
TAILQ_ENTRY(h2_stream_data_t) next;
|
||||
|
||||
int32_t stream_id;
|
||||
uint16_t frame_type;
|
||||
|
||||
int spd_set;
|
||||
int spd_valid;
|
||||
|
||||
@@ -46,6 +46,7 @@ static const struct value_string method_vals[] =
|
||||
{NGHTTP2_METHOD_POST, "POST"},
|
||||
{NGHTTP2_METHOD_PUT, "PUT"},
|
||||
{NGHTTP2_METHOD_CONNECT, "CONNECT"},
|
||||
{NGHTTP2_METHOD_OPTIONS, "OPTIONS"},
|
||||
{NGHTTP2_METHOD_UNKNOWN, "unknown"},
|
||||
};
|
||||
|
||||
@@ -803,8 +804,8 @@ nghttp2_submit_frame_rst_stream(struct tfe_session_info_t *session_info,const ng
|
||||
}
|
||||
finish:
|
||||
session_info->stream_action = stream_action;
|
||||
TFE_LOG_INFO(logger()->handle, "%s, %d, submit rst stream, stream_id:%d, action:%d", session_info->tf_stream->str_stream_info,
|
||||
dir, frame->hd.stream_id, session_info->stream_action);
|
||||
TFE_LOG_INFO(logger()->handle, "%s, %d, submit rst stream, stream_id:%d, action:%d, error_code = %d", session_info->tf_stream->str_stream_info,
|
||||
dir, frame->hd.stream_id, session_info->stream_action, rst_stream->error_code);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -879,6 +880,41 @@ finish:
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
nghttp2_write_access_log(struct h2_stream_data_t *h2_stream, const char * str_stream_info)
|
||||
{
|
||||
/* Request */
|
||||
struct http2_half_private *req = h2_stream->req;
|
||||
/* Response */
|
||||
struct http2_half_private *resp = h2_stream->resp;
|
||||
/* Req-Public */
|
||||
struct tfe_http_req_spec *req_spec = req ? &(req->half_public.req_spec) : NULL;
|
||||
/* Resp-Public */
|
||||
struct tfe_http_resp_spec *resp_spec = resp ? &(resp->half_public.resp_spec) : NULL;
|
||||
|
||||
const char * method = req_spec ? val_to_str(req_spec->method, method_vals) : "-";
|
||||
const char * url = req_spec ? req_spec->url : "-";
|
||||
char resp_code[TFE_STRING_MAX];
|
||||
if (resp_spec)
|
||||
snprintf(resp_code, sizeof(resp_code) - 1, "%d", resp_spec->resp_code);
|
||||
else
|
||||
snprintf(resp_code, sizeof(resp_code) - 1, "%s", "-");
|
||||
|
||||
const char * cont_type = resp_spec ? resp_spec->content_type != NULL ? resp_spec->content_type : "-" : "-";
|
||||
const char * cont_encoding =
|
||||
resp_spec ? resp_spec->content_encoding != NULL ? resp_spec->content_encoding : "-" : "-";
|
||||
const char * pangu_req = h2_stream->pangu_req ? "USER/REQ" : "-";
|
||||
const char * pangu_resp = h2_stream->pangu_resp ? "USER/RESP" : "-";
|
||||
//const char * __str_suspend = h2_stream->suspend_counter > 0 ? "SUSPEND" : "-";
|
||||
|
||||
char *access_log;
|
||||
asprintf(&access_log, "%s %d %s %s HTTP2.0 %s %s %s %s %s", str_stream_info, h2_stream->tfe_session.session_id,
|
||||
method, url, resp_code, cont_type, cont_encoding, pangu_req, pangu_resp);
|
||||
|
||||
TFE_LOG_INFO(logger()->handle, "%s", access_log);
|
||||
free(access_log);
|
||||
}
|
||||
|
||||
void delete_http2_stream_data(struct h2_stream_data_t *h2_stream,
|
||||
const struct tfe_stream *tf_stream,
|
||||
int body_flag)
|
||||
@@ -1267,6 +1303,42 @@ nghttp2_headers_write_log(struct h2_stream_data_t *h2_stream, const char * str_s
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
nghttp2_end_submit_header2(struct tfe_session_info_t *session_info,
|
||||
struct h2_stream_data_t *h2_stream)
|
||||
{
|
||||
int xret = -1;
|
||||
int32_t stream_id = 0;
|
||||
nghttp2_nv hdrs[128] = {0};
|
||||
struct http2_headers headers;
|
||||
struct http2_half_private *resp = h2_stream->resp;
|
||||
enum tfe_stream_action stream_action = ACTION_DROP_DATA;
|
||||
|
||||
headers = resp->headers;
|
||||
if (headers.nvlen <= 0){
|
||||
goto finish;
|
||||
}
|
||||
stream_id = nghttp2_submit_headers(session_info->as_server, headers.flag,
|
||||
h2_stream->stream_id, NULL, nghttp2_nv_packet(&headers, hdrs),
|
||||
headers.nvlen, h2_stream);
|
||||
if (stream_id < 0){
|
||||
printf("Fatal headers error: %s\n", nghttp2_strerror(stream_id));
|
||||
stream_action = ACTION_FORWARD_DATA;
|
||||
}
|
||||
delete_nv_packet_data(&headers);
|
||||
|
||||
if (stream_action == ACTION_DROP_DATA){
|
||||
xret = nghttp2_session_send(session_info->as_server);
|
||||
if (xret != 0) {
|
||||
stream_action = ACTION_FORWARD_DATA;
|
||||
TFE_LOG_ERROR(logger()->handle, "Fatal upstream send error: %s\n",nghttp2_strerror(xret));
|
||||
}
|
||||
}
|
||||
finish:
|
||||
session_info->stream_action = stream_action;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
nghttp2_server_submit_header(struct tfe_session_info_t *session_info, int32_t stream_id)
|
||||
{
|
||||
@@ -1694,7 +1766,7 @@ nghttp2_data_send(nghttp2_session *session, const nghttp2_frame *frame, const ui
|
||||
return (ssize_t)length;
|
||||
}
|
||||
|
||||
static void
|
||||
static int
|
||||
submit_end_data(struct tfe_session_info_t *session_info,
|
||||
struct h2_stream_data_t *h2_stream)
|
||||
{
|
||||
@@ -1702,6 +1774,12 @@ submit_end_data(struct tfe_session_info_t *session_info,
|
||||
enum tfe_stream_action stream_action = ACTION_DROP_DATA;
|
||||
|
||||
struct http2_half_private *resp = h2_stream->resp;
|
||||
|
||||
if (resp->body_state == MANAGE_STAGE_INIT){
|
||||
nghttp2_end_submit_header2(session_info, h2_stream);
|
||||
//return 1;
|
||||
}
|
||||
|
||||
if (resp->body_state != MANAGE_STAGE_INIT){
|
||||
if (resp->event_cb) {
|
||||
resp->event_cb(resp, EV_HTTP_RESP_BODY_END, NULL, 0,
|
||||
@@ -1731,7 +1809,7 @@ submit_end_data(struct tfe_session_info_t *session_info,
|
||||
if (stream_action == ACTION_USER_DATA)
|
||||
stream_action = ACTION_DROP_DATA;
|
||||
session_info->stream_action = stream_action;
|
||||
return;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -1739,6 +1817,7 @@ nghttp2_on_stream_close(nghttp2_session *session, const nghttp2_frame *frame, co
|
||||
size_t namelen, const uint8_t *value,
|
||||
size_t valuelen, uint8_t flags, void *user_data, enum tfe_conn_dir dir)
|
||||
{
|
||||
int xret = -1;
|
||||
struct h2_stream_data_t *h2_stream = NULL;
|
||||
struct http2_half_private *resp = NULL;
|
||||
|
||||
@@ -1760,8 +1839,9 @@ nghttp2_on_stream_close(nghttp2_session *session, const nghttp2_frame *frame, co
|
||||
|
||||
resp = h2_stream->resp;
|
||||
if (error_code == 0 && resp->body_state != MANAGE_STAGE_COMPLETE){
|
||||
submit_end_data(session_info, h2_stream);
|
||||
goto end;
|
||||
xret = submit_end_data(session_info, h2_stream);
|
||||
if (xret == 1)
|
||||
goto end;
|
||||
}
|
||||
finish:
|
||||
TAILQ_REMOVE(&session_info->list, h2_stream, next);
|
||||
@@ -1788,41 +1868,6 @@ nghttp2_callback nghttp2_callback_array[] = {
|
||||
[NGHTTP2_USER_COLSE] = nghttp2_on_stream_close
|
||||
};
|
||||
|
||||
void
|
||||
nghttp2_write_access_log(struct h2_stream_data_t *h2_stream, const char * str_stream_info)
|
||||
{
|
||||
/* Request */
|
||||
struct http2_half_private *req = h2_stream->req;
|
||||
/* Response */
|
||||
struct http2_half_private *resp = h2_stream->resp;
|
||||
/* Req-Public */
|
||||
struct tfe_http_req_spec *req_spec = req ? &(req->half_public.req_spec) : NULL;
|
||||
/* Resp-Public */
|
||||
struct tfe_http_resp_spec *resp_spec = resp ? &(resp->half_public.resp_spec) : NULL;
|
||||
|
||||
const char * method = req_spec ? val_to_str(req_spec->method, method_vals) : "-";
|
||||
const char * url = req_spec ? req_spec->url : "-";
|
||||
char resp_code[TFE_STRING_MAX];
|
||||
if (resp_spec)
|
||||
snprintf(resp_code, sizeof(resp_code) - 1, "%d", resp_spec->resp_code);
|
||||
else
|
||||
snprintf(resp_code, sizeof(resp_code) - 1, "%s", "-");
|
||||
|
||||
const char * cont_type = resp_spec ? resp_spec->content_type != NULL ? resp_spec->content_type : "-" : "-";
|
||||
const char * cont_encoding =
|
||||
resp_spec ? resp_spec->content_encoding != NULL ? resp_spec->content_encoding : "-" : "-";
|
||||
const char * pangu_req = h2_stream->pangu_req ? "USER/REQ" : "-";
|
||||
const char * pangu_resp = h2_stream->pangu_resp ? "USER/RESP" : "-";
|
||||
//const char * __str_suspend = h2_stream->suspend_counter > 0 ? "SUSPEND" : "-";
|
||||
|
||||
char *access_log;
|
||||
asprintf(&access_log, "%s %d %s %s HTTP2.0 %s %s %s %s %s", str_stream_info, h2_stream->tfe_session.session_id,
|
||||
method, url, resp_code, cont_type, cont_encoding, pangu_req, pangu_resp);
|
||||
|
||||
TFE_LOG_INFO(logger()->handle, "%s", access_log);
|
||||
free(access_log);
|
||||
}
|
||||
|
||||
static ssize_t
|
||||
nghttp2_client_send(nghttp2_session *session, const uint8_t *data,
|
||||
size_t length, int flags, void *user_data)
|
||||
@@ -1914,12 +1959,12 @@ nghttp2_client_on_data_chunk_recv(nghttp2_session *session, uint8_t flags,
|
||||
TFE_LOG_ERROR(logger()->handle, "Fatal upstream send error: %s\n",nghttp2_strerror(xret));
|
||||
}
|
||||
}
|
||||
TFE_LOG_INFO(logger()->handle, "%s, 1, submit data %d, stream_id:%d, action:%d", session_info->tf_stream->str_stream_info,
|
||||
(int)input_len, stream_id, stream_action);
|
||||
if (stream_action == ACTION_USER_DATA)
|
||||
stream_action = ACTION_DROP_DATA;
|
||||
session_info->stream_action = stream_action;
|
||||
finish:
|
||||
TFE_LOG_INFO(logger()->handle, "%s, 1, submit data %d, stream_id:%d, action:%d", session_info->tf_stream->str_stream_info,
|
||||
(int)input_len, stream_id, session_info->stream_action);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -2357,7 +2402,6 @@ detect_down_stream_protocol(struct tfe_session_info_t *session_info, const struc
|
||||
}
|
||||
stream_action = session_info->stream_action;
|
||||
session_info->stream_action = ACTION_DROP_DATA;
|
||||
// printf("down stream_acion = %d\n", stream_action);
|
||||
if (stream_action == ACTION_FORWARD_DATA){
|
||||
xret = nghttp2_session_send(session_info->as_server);
|
||||
if (xret != 0) {
|
||||
|
||||
2
vendor/CMakeLists.txt
vendored
2
vendor/CMakeLists.txt
vendored
@@ -81,7 +81,7 @@ set_property(TARGET http-parser-static PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${
|
||||
ExternalProject_Add(nghttp2
|
||||
PREFIX nghttp2
|
||||
URL ${CMAKE_CURRENT_SOURCE_DIR}/nghttp2-1.24.0.tar.gz
|
||||
URL_MD5 66d78a8b968d78ffa34b219a571a39b6
|
||||
URL_MD5 214f4e02980ea1644ea9e11a60897bed
|
||||
CONFIGURE_COMMAND ./configure --prefix=<INSTALL_DIR> --disable-shared
|
||||
BUILD_IN_SOURCE 1)
|
||||
|
||||
|
||||
BIN
vendor/nghttp2-1.24.0.tar.gz
vendored
BIN
vendor/nghttp2-1.24.0.tar.gz
vendored
Binary file not shown.
Reference in New Issue
Block a user