diff options
| author | fengweihao <[email protected]> | 2019-07-21 23:14:31 +0800 |
|---|---|---|
| committer | fengweihao <[email protected]> | 2019-07-21 23:14:31 +0800 |
| commit | 90269816e363add4a38497a8f9bafb107c026c06 (patch) | |
| tree | b68be54598273d54fe8a3a56743a9563579cce6f /plugin/protocol/http2/src/http2_stream.cpp | |
| parent | e780eeae93bdbf2002263ff34e524a0f3b862313 (diff) | |
1.修复chello为空导致访问越界
2.修复twitter字符编码为charset=“utf-8”,原判断可能存在问题
3.修复http2页面替换,由于存在use_half,而无数据域,造成页面卡顿
4.修复http2替换时,由于解码失败,造成页面无法发送
Diffstat (limited to 'plugin/protocol/http2/src/http2_stream.cpp')
| -rw-r--r-- | plugin/protocol/http2/src/http2_stream.cpp | 109 |
1 files changed, 83 insertions, 26 deletions
diff --git a/plugin/protocol/http2/src/http2_stream.cpp b/plugin/protocol/http2/src/http2_stream.cpp index 5d71df1..734fd88 100644 --- a/plugin/protocol/http2/src/http2_stream.cpp +++ b/plugin/protocol/http2/src/http2_stream.cpp @@ -753,11 +753,13 @@ nghttp2_frame_submit_built_resp(struct tfe_h2_stream *h2_stream_info, { int rv = -1; struct tfe_h2_header *h2_header = NULL; - struct tfe_h2_half_private *pangu_resp = NULL; - + struct tfe_h2_half_private *pangu_resp = NULL, *resp = NULL; + + resp = h2_session->resp; pangu_resp = h2_session->plugin_built_resp; - if (pangu_resp->message_state != H2_READ_STATE_COMPLETE){ + if (pangu_resp->message_state != H2_READ_STATE_COMPLETE && (evbuffer_get_length(resp->h2_payload.evbuf_body) > 0)) + { return (enum tfe_stream_action)ACTION_USER_DATA; } h2_header = &pangu_resp->header; @@ -862,6 +864,32 @@ nghttp2_submit_end_data_by_h2_half(struct tfe_h2_stream *h2_stream_info, int32_t } static enum tfe_stream_action +nghttp2_submit_data_by_user(struct tfe_h2_stream *connection, + struct tfe_h2_session *h2_session, + enum tfe_conn_dir dir) +{ + int rv = -1; + enum tfe_stream_action stream_action = ACTION_DROP_DATA; + + struct tfe_h2_half_private *h2_half = tfe_h2_stream_get_half(h2_session, dir); + nghttp2_session *ngh2_session = tfe_h2_stream_get_nghttp2_session(connection, dir); + + struct tfe_h2_payload *body = &h2_half->h2_payload; + + nghttp2_data_provider upstream_data_provider; + upstream_data_provider.source.ptr = (void *)body; + upstream_data_provider.read_callback = upstream_read_callback; + + rv = nghttp2_submit_data(ngh2_session, body->flags, + h2_session->ngh2_stream_id, &upstream_data_provider); + if (rv != 0){ + stream_action = ACTION_FORWARD_DATA; + //printf("Fatal server submit data error: %s\n", nghttp2_strerror(rv)); + } + return stream_action; +} + +static enum tfe_stream_action nghttp2_submit_data_by_h2_half(struct tfe_h2_stream *connection, struct tfe_h2_session *h2_session, enum tfe_conn_dir dir) @@ -890,7 +918,8 @@ nghttp2_submit_data_by_h2_half(struct tfe_h2_stream *connection, rv = nghttp2_submit_data(ngh2_session, body->flags, h2_session->ngh2_stream_id, &upstream_data_provider); - if (rv != 0){ + if (rv != 0) + { stream_action = ACTION_FORWARD_DATA; //printf("Fatal server submit data error: %s\n", nghttp2_strerror(rv)); } @@ -1228,11 +1257,13 @@ nghttp2_submit_complete_data(struct tfe_h2_stream *h2_stream_info, if (h2_half->body_state != H2_READ_STATE_BEGIN) { - if (h2_half->event_cb) { + if (h2_half->event_cb) + { h2_half->event_cb(h2_half, http_body_event, NULL, 0, - h2_half->event_cb_user); + h2_half->event_cb_user); } - if (h2_half->event_cb) { + if (h2_half->event_cb) + { h2_half->event_cb(h2_half, http_event, NULL, 0, h2_half->event_cb_user); } @@ -1243,9 +1274,11 @@ nghttp2_submit_complete_data(struct tfe_h2_stream *h2_stream_info, h2_half->message_state = H2_READ_STATE_COMPLETE; stream_action = nghttp2_submit_data_by_h2_half(h2_stream_info, h2_session, dir); - if (stream_action == ACTION_DROP_DATA){ + if (stream_action == ACTION_DROP_DATA) + { xret = nghttp2_session_send(ngh2_session); - if (xret != 0) { + if (xret != 0) + { stream_action = ACTION_FORWARD_DATA; TFE_LOG_ERROR(logger()->handle, "Fatal upstream send error: %s %d\n",nghttp2_strerror(xret), __LINE__); } @@ -2053,52 +2086,74 @@ nghttp2_client_on_data_chunk_recv(nghttp2_session *session, uint8_t flags, { h2_stream_info->stream_action = ACTION_DROP_DATA; return 0; - } - + } evbuffer_add(resp->h2_payload.evbuf_body, input, input_len); - if (resp->h2_payload.gzip != HTTP2_CONTENT_ENCODING_NONE){ + if (resp->h2_payload.gzip != HTTP2_CONTENT_ENCODING_NONE) + { ret = inflate_read(input, input_len, &uncompr, &uncompr_len, &resp->h2_payload.inflate, resp->h2_payload.gzip); - if (((ret == Z_STREAM_END) || (ret == Z_OK)) && uncompr > 0){ + if (((ret == Z_STREAM_END) || (ret == Z_OK)) && uncompr_len > 0) + { input = (const uint8_t*)uncompr; input_len = uncompr_len; - }else + } + else { - if (uncompr_len) FREE(&uncompr); + stream_action = nghttp2_submit_data_by_user(h2_stream_info, h2_session, CONN_DIR_UPSTREAM); + if (stream_action == ACTION_DROP_DATA) + { + xret = nghttp2_session_send(h2_stream_info->as_server); + if (xret != 0) + { + stream_action = ACTION_FORWARD_DATA; + TFE_LOG_ERROR(logger()->handle, "Fatal upstream(%d) send error: %s\n",stream_id, nghttp2_strerror(xret)); + } + } + h2_stream_info->stream_action = stream_action; + return 0; } } data = input; len = input_len; - if (resp->body_state == H2_READ_STATE_BEGIN){ - if (resp->event_cb) { + if (resp->body_state == H2_READ_STATE_BEGIN) + { + if (resp->event_cb) + { resp->event_cb(resp, EV_HTTP_RESP_BODY_BEGIN, NULL, len, resp->event_cb_user); } - if (flags == NGHTTP2_FLAG_END_STREAM){ + if (flags == NGHTTP2_FLAG_END_STREAM) + { resp->h2_payload.flags = NGHTTP2_FLAG_NONE; - }else{ + }else + { resp->h2_payload.flags = flags; } resp->body_state = H2_READ_STATE_READING; } - if (resp->body_state == H2_READ_STATE_READING){ - if (resp->event_cb) { + if (resp->body_state == H2_READ_STATE_READING) + { + if (resp->event_cb) + { resp->event_cb(resp, EV_HTTP_RESP_BODY_CONT, data, len, resp->event_cb_user); } - if (flags == NGHTTP2_FLAG_END_STREAM){ + if (flags == NGHTTP2_FLAG_END_STREAM) + { resp->h2_payload.flags = NGHTTP2_FLAG_NONE; - }else{ + }else + { resp->h2_payload.flags = flags; } } if (uncompr_len) FREE(&uncompr); - stream_action = nghttp2_submit_data_by_h2_half(h2_stream_info, h2_session, CONN_DIR_UPSTREAM); - if (stream_action == ACTION_DROP_DATA){ + if (stream_action == ACTION_DROP_DATA) + { xret = nghttp2_session_send(h2_stream_info->as_server); - if (xret != 0) { + if (xret != 0) + { stream_action = ACTION_FORWARD_DATA; TFE_LOG_ERROR(logger()->handle, "Fatal upstream(%d) send error: %s\n",stream_id, nghttp2_strerror(xret)); } @@ -2489,6 +2544,8 @@ server_session_init(struct tfe_h2_stream *h2_stream_info) callbacks, nghttp2_server_on_begin_headers); nghttp2_session_server_new(&h2_stream_info->as_server, callbacks, h2_stream_info); + + h2_stream_info->as_server->opt_flags |= NGHTTP2_OPTMASK_NO_CLOSED_STREAMS; nghttp2_session_callbacks_del(callbacks); } |
