From 1e5a9a537d757493d19e5bf9c02559928f07637d Mon Sep 17 00:00:00 2001 From: fengweihao Date: Mon, 8 Jul 2019 16:58:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dtwitter=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E6=98=BE=E7=A4=BA=E9=97=AE=E9=A2=98=EF=BC=8C?= =?UTF-8?q?=E5=8E=9F=E5=9B=A0=E4=B8=BA=E6=B3=A8=E5=86=8CEND=5FSTREAM?= =?UTF-8?q?=E6=97=B6=E4=BC=A0=E5=8F=82=E9=94=99=E8=AF=AF,=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E8=8E=B7=E5=8F=96=E5=8F=96half=E5=80=BC=E6=97=B6?= =?UTF-8?q?=E6=96=B9=E5=90=91=E9=94=99=E8=AF=AF=20http2=E6=B3=A8=E5=86=8C?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E5=A4=B4=E6=97=B6=EF=BC=8C=E4=B8=8D=E5=9C=A8?= =?UTF-8?q?=E5=8C=BA=E5=88=86post/get?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/business/pangu-http/src/pangu_http.cpp | 6 +-- plugin/protocol/http2/src/http2_stream.cpp | 45 ++++++++----------- 2 files changed, 21 insertions(+), 30 deletions(-) diff --git a/plugin/business/pangu-http/src/pangu_http.cpp b/plugin/business/pangu-http/src/pangu_http.cpp index b77f37e..ba734ea 100644 --- a/plugin/business/pangu-http/src/pangu_http.cpp +++ b/plugin/business/pangu-http/src/pangu_http.cpp @@ -1411,13 +1411,11 @@ void http_replace(const struct tfe_stream * stream, const struct tfe_http_sessio rewrite_buff = NULL; rewrite_sz = 0; - if (tfe_http_in_response(events) && in_resp_spec->content_type != NULL - && (strstr(in_resp_spec->content_type, "charset=utf-8") || - (strstr(in_resp_spec->content_type, "charset=UTF-8")))) + if (tfe_http_in_response(events) && in_resp_spec->content_type != NULL + && strcasestr(in_resp_spec->content_type, "charset=utf-8")) { options = 1; } - rewrite_sz = execute_replace_rule(__http_body, __http_body_len, r_zone, rep_ctx->rule, rep_ctx->n_rule, &rewrite_buff, options); diff --git a/plugin/protocol/http2/src/http2_stream.cpp b/plugin/protocol/http2/src/http2_stream.cpp index 878d466..4565c14 100644 --- a/plugin/protocol/http2/src/http2_stream.cpp +++ b/plugin/protocol/http2/src/http2_stream.cpp @@ -157,7 +157,7 @@ tfe_h2_header_modify_field(struct tfe_h2_header *header, nghttp2_nv *hdrs, const { hdrs[nvlen].value = h2_field->nv.value; hdrs[nvlen].valuelen = h2_field->nv.valuelen; - } + } hdrs[nvlen].flags = h2_field->nv.flags; nvlen++; } @@ -864,9 +864,9 @@ nghttp2_submit_data_by_h2_half(struct tfe_h2_stream *connection, struct tfe_h2_session *h2_session, enum tfe_conn_dir dir) { - enum tfe_stream_action stream_action = ACTION_DROP_DATA; - - struct tfe_h2_half_private *h2_half = (dir == CONN_DIR_UPSTREAM) ? h2_session->resp : h2_session->req; + 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); if (h2_session->plugin_built_resp) @@ -1239,7 +1239,7 @@ nghttp2_submit_complete_data(struct tfe_h2_stream *h2_stream_info, h2_half->body_state = H2_READ_STATE_COMPLETE; h2_half->message_state = H2_READ_STATE_COMPLETE; - stream_action = nghttp2_submit_data_by_h2_half(h2_stream_info, h2_session, CONN_DIR_UPSTREAM); + stream_action = nghttp2_submit_data_by_h2_half(h2_stream_info, h2_session, dir); if (stream_action == ACTION_DROP_DATA){ xret = nghttp2_session_send(ngh2_session); if (xret != 0) { @@ -1650,7 +1650,7 @@ finish: return 0; } -static int fill_req_spec_from_handle(struct tfe_h2_half_private *half_private) +static void fill_req_spec_from_handle(struct tfe_h2_half_private *half_private) { int urllen = 0; struct tfe_h2_field *h2_field = NULL, *peer_h2_field = NULL; @@ -1677,10 +1677,8 @@ static int fill_req_spec_from_handle(struct tfe_h2_half_private *half_private) if(urltmp){ sprintf(urltmp, "%s%s", (char *)req_spec->host, (char *)req_spec->uri); req_spec->url = urltmp; - if (strcasestr(urltmp, "twitter")) - return 1; } - return 0; + return; } #ifdef TFE_CACHE @@ -1728,7 +1726,7 @@ finish: static enum tfe_stream_action nghttp2_client_frame_submit_header(struct tfe_h2_stream *h2_stream_info, - struct tfe_h2_session *h2_session, int twitter) + struct tfe_h2_session *h2_session) { int32_t stream_id = -1; struct tfe_h2_header *headers = NULL; @@ -1757,24 +1755,19 @@ nghttp2_client_frame_submit_header(struct tfe_h2_stream *h2_stream_info, return ACTION_FORWARD_DATA; } - nghttp2_nv hdrs[headers->nvlen]; - method = nghttp2_get_method(h2_session->req); - if ((method == (enum tfe_http_std_method)NGHTTP2_METHOD_POST || - method == (enum tfe_http_std_method)NGHTTP2_METHOD_PUT) && twitter != 1){ - if (h2_session->plugin_built_req) + if (method == (enum tfe_http_std_method)NGHTTP2_METHOD_POST || method == (enum tfe_http_std_method)NGHTTP2_METHOD_PUT) + { + if (h2_session->plugin_built_req != NULL) { stream_action = (enum tfe_stream_action)ACTION_USER_DATA; return stream_action; } - stream_id = nghttp2_submit_headers(h2_stream_info->as_client, headers->flag, - -1, NULL, tfe_h2_header_modify_field(headers, hdrs, ":path", req->url_storage), - headers->nvlen, h2_session); - }else{ - stream_id = nghttp2_submit_request(h2_stream_info->as_client, NULL, - tfe_h2_header_modify_field(headers, hdrs, ":path", req->url_storage), - headers->nvlen, NULL, h2_session); - } + } + nghttp2_nv hdrs[headers->nvlen]; + stream_id = nghttp2_submit_headers(h2_stream_info->as_client, headers->flag, + -1, NULL, tfe_h2_header_modify_field(headers, hdrs, ":path", req->url_storage), + headers->nvlen, h2_session); if (stream_id < 0){ TFE_LOG_ERROR(logger()->handle, "Could not submit request: %s", nghttp2_strerror(stream_id)); @@ -1790,7 +1783,7 @@ finish: static int nghttp2_client_submit_header(struct tfe_h2_stream *h2_stream_info, int32_t stream_id) { - int xret = -1, twitter = 1; + int xret = -1; struct tfe_h2_half_private *req = NULL; struct tfe_h2_session *h2_session = NULL; @@ -1805,12 +1798,12 @@ nghttp2_client_submit_header(struct tfe_h2_stream *h2_stream_info, int32_t strea assert(h2_session->ngh2_stream_id == stream_id); req = h2_session->req; - twitter = fill_req_spec_from_handle(h2_session->req); + fill_req_spec_from_handle(h2_session->req); req->event_cb(req, EV_HTTP_REQ_HDR, NULL, 0, req->event_cb_user); nghttp2_write_log(h2_session, h2_stream_info->tf_stream->str_stream_info, CONN_DIR_DOWNSTREAM); - stream_action = nghttp2_client_frame_submit_header(h2_stream_info, h2_session, twitter); + stream_action = nghttp2_client_frame_submit_header(h2_stream_info, h2_session); if (stream_action == ACTION_DROP_DATA){ xret = nghttp2_session_send(h2_stream_info->as_client); if (xret != 0) {