From 0b77bc0fc87009d80a52336707de1339f9657e34 Mon Sep 17 00:00:00 2001 From: fengweihao Date: Thu, 22 Aug 2019 14:10:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3HTTP2=E6=9E=84=E5=BB=BA?= =?UTF-8?q?=E6=96=B0=E5=A4=B4=E9=83=A8=E6=97=B6=E5=A4=84=E7=90=86=E5=A4=9A?= =?UTF-8?q?=E4=B8=AA=E5=85=B7=E6=9C=89=E7=9B=B8=E5=90=8C=E5=90=8D=E7=A7=B0?= =?UTF-8?q?=E5=A4=B4=E9=83=A8=E5=AD=97=E6=AE=B5=E7=9A=84=E5=A4=84=E7=90=86?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/protocol/http2/src/http2_stream.cpp | 50 ++++++++++------------ 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/plugin/protocol/http2/src/http2_stream.cpp b/plugin/protocol/http2/src/http2_stream.cpp index a45d2fb..cf8593b 100644 --- a/plugin/protocol/http2/src/http2_stream.cpp +++ b/plugin/protocol/http2/src/http2_stream.cpp @@ -337,36 +337,29 @@ int h2_half_ops_field_write(struct tfe_http_half * half, const struct http_field struct tfe_h2_header *h2_header = &(half_private->header); struct tfe_h2_field *h2_field=NULL,*peer_h2_field=NULL; - TAILQ_FOREACH(h2_field, &h2_header->h2_field_list, next) - { - if (http_field_name_compare(h2_field->field, field) != 0) continue; - peer_h2_field = h2_field; - break; - } - - if (peer_h2_field != NULL && value != NULL) - { - FREE(&(peer_h2_field->nv.value)); - peer_h2_field->nv.value = (uint8_t*)tfe_strdup(value); - peer_h2_field->nv.valuelen = strlen(value); - } - else if (peer_h2_field != NULL && value == NULL) - { - TAILQ_REMOVE(&h2_header->h2_field_list, peer_h2_field, next); - free(peer_h2_field->nv.name); - free(peer_h2_field->nv.value); - free(peer_h2_field); - h2_header->nvlen--; - } - else if (peer_h2_field == NULL && value != NULL) + if (value != NULL) { tfe_h2_header_add_field(h2_header, field, value, 1); } else { - return -1; - } + bool delete_success = false; + TAILQ_FOREACH_SAFE(h2_field, &h2_header->h2_field_list, next, peer_h2_field) + { + if (http_field_name_compare(h2_field->field, field) != 0) + continue; + + TAILQ_REMOVE(&h2_header->h2_field_list, h2_field, next); + free(h2_field->nv.name); + free(h2_field->nv.value); + free(h2_field); + h2_header->nvlen--; + delete_success = true; + } + + return delete_success ? 0 : -ENOENT; + } return 0; } @@ -779,13 +772,15 @@ nghttp2_frame_submit_built_resp(struct tfe_h2_stream *h2_stream_info, char str_sz_evbuf_body[TFE_STRING_MAX]; snprintf(str_sz_evbuf_body, sizeof(str_sz_evbuf_body) - 1, "%lu", evbuffer_get_length(body->evbuf_body)); - const static struct http_field_name cont_field = {TFE_HTTP_CONT_LENGTH, NULL}; + const static struct http_field_name cont_field = {TFE_HTTP_CONT_LENGTH, NULL}; + tfe_http_field_write(&pangu_resp->half_public, &cont_field, NULL); tfe_http_field_write(&pangu_resp->half_public, &cont_field, str_sz_evbuf_body); if (body->gzip != HTTP2_CONTENT_ENCODING_NONE) { const static struct http_field_name encoding_field = {TFE_HTTP_CONT_ENCODING, NULL}; - const char *content_encoding = method_idx_to_str(body->gzip); + const char *content_encoding = method_idx_to_str(body->gzip); + tfe_http_field_write(&pangu_resp->half_public, &encoding_field, NULL); tfe_http_field_write(&pangu_resp->half_public, &encoding_field, content_encoding); } @@ -826,7 +821,8 @@ nghttp2_frame_submit_built_req(struct tfe_h2_stream *h2_stream_info, char str_sz_evbuf_body[TFE_STRING_MAX]; snprintf(str_sz_evbuf_body, sizeof(str_sz_evbuf_body) - 1, "%lu", evbuffer_get_length(body->evbuf_body)); - const static struct http_field_name encoding_field = {TFE_HTTP_CONT_LENGTH, NULL}; + const static struct http_field_name encoding_field = {TFE_HTTP_CONT_LENGTH, NULL}; + tfe_http_field_write(&plugin_built_req->half_public, &encoding_field, NULL); tfe_http_field_write(&plugin_built_req->half_public, &encoding_field, str_sz_evbuf_body); nghttp2_data_provider data_prd;