From aa88471f2564da19e2f6a1b8e01fc5393316be99 Mon Sep 17 00:00:00 2001 From: fengweihao Date: Wed, 31 Jul 2019 13:45:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=AE=8B=E7=95=99=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=EF=BC=8C=E9=80=A0=E6=88=90select=5Fpadding=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E6=AE=B5=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/protocol/http2/src/http2_common.cpp | 35 ++++++++++------------ plugin/protocol/http2/src/http2_stream.cpp | 29 +++++++++--------- 2 files changed, 29 insertions(+), 35 deletions(-) diff --git a/plugin/protocol/http2/src/http2_common.cpp b/plugin/protocol/http2/src/http2_common.cpp index c58eb9c..2847ce5 100644 --- a/plugin/protocol/http2/src/http2_common.cpp +++ b/plugin/protocol/http2/src/http2_common.cpp @@ -372,38 +372,33 @@ int deflate_write(struct z_stream_st **strm, const uint8_t *source, void inflate_finished(struct z_stream_st **strm) { if (*strm != NULL){ - if ((*strm)->brdec_state){ + if ((*strm)->brdec_state) + { BrotliDecoderDestroyInstance((*strm)->brdec_state); - (*strm)->brdec_state = NULL; - return; + (*strm)->brdec_state = NULL; + goto finish; } (void)inflateEnd(&((*strm)->zst)); +finish: free(*strm); *strm = NULL; } } void deflate_finished(struct z_stream_st **strm) { - if (*strm != NULL){ + if (*strm != NULL) + { + if ((*strm)->brenc_state) + { + BrotliEncoderDestroyInstance((*strm)->brenc_state); + (*strm)->brenc_state = NULL; + goto finish; + + } (void) deflateEnd(&((*strm)->zst)); +finish: free(*strm); *strm = NULL; } } -void frame_display(const uint8_t *payload, uint16_t payload_len) -{ - int i = 0; - - printf("context:(%d)\n", payload_len); - for(i=0; i < (int)payload_len; ++i){ - printf(" 0x%02x,", payload[i]); - if( (i + 1) % 16 == 0) - printf("\n"); - if ( i > 500) - break; - } - printf("\n\n"); -} - - diff --git a/plugin/protocol/http2/src/http2_stream.cpp b/plugin/protocol/http2/src/http2_stream.cpp index 806037f..a45d2fb 100644 --- a/plugin/protocol/http2/src/http2_stream.cpp +++ b/plugin/protocol/http2/src/http2_stream.cpp @@ -1056,19 +1056,17 @@ nghttp2_submit_frame_ping(struct tfe_h2_stream *connection,const nghttp2_frame * nghttp2_session *ngh2_session = tfe_h2_stream_get_nghttp2_session(connection, dir); - rv = nghttp2_submit_ping(ngh2_session, ping->hd.flags, - ping->opaque_data); - if (rv != 0){ + rv = nghttp2_submit_ping(ngh2_session, ping->hd.flags, ping->opaque_data); + if (rv != 0) + { stream_action = ACTION_FORWARD_DATA; - TFE_LOG_ERROR(logger()->handle, "dir(%d), Submit ping error: %s\n", - dir, nghttp2_strerror(rv)); + TFE_LOG_ERROR(logger()->handle, "dir(%d), Submit ping error: %s\n", dir, nghttp2_strerror(rv)); return 0; } xret = nghttp2_session_send(ngh2_session); if (xret != 0) { stream_action = ACTION_FORWARD_DATA; - TFE_LOG_ERROR(logger()->handle, "dir(%d), Fatal send error: %s\n", - dir, nghttp2_strerror(xret)); + TFE_LOG_ERROR(logger()->handle, "dir(%d), Fatal send error: %s\n", dir, nghttp2_strerror(xret)); } connection->stream_action = stream_action; return 0; @@ -1842,7 +1840,8 @@ 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; - fill_req_spec_from_handle(h2_session->req); + fill_req_spec_from_handle(h2_session->req); + h2_stream_info->as_client->last_sent_stream_id = MIN(h2_stream_info->as_client->last_sent_stream_id, stream_id) - 1; req->event_cb(req, EV_HTTP_REQ_HDR, NULL, 0, req->event_cb_user); @@ -2260,15 +2259,15 @@ static ssize_t nghttp2_client_select_padding_callback(nghttp2_session *session, size_t max_payloadlen, void *user_data) { struct tfe_h2_half_private *resp = NULL; - struct tfe_h2_session *h2_session = NULL; - - h2_session = (struct tfe_h2_session *)nghttp2_session_get_stream_user_data(session, frame->hd.stream_id); - if (!h2_session) - return frame->hd.length; + struct tfe_h2_stream *h2_stream_info = (struct tfe_h2_stream *)user_data; + + struct tfe_h2_session *h2_session = TAILQ_LIST_FIND(h2_stream_info, frame->hd.stream_id); + if (h2_session == NULL) return frame->hd.length; + resp = h2_session->resp; - if (!resp) + if (resp == NULL) return frame->hd.length; - + return (ssize_t)MIN(max_payloadlen, frame->hd.length + (resp->h2_payload.padlen)); }