From b689485fea524850f5f0c11bbc21d90ba40e15a6 Mon Sep 17 00:00:00 2001 From: luqiuwen Date: Thu, 22 Aug 2019 11:17:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3HTTP1=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=E3=80=82=20*=20=E5=8E=9F=E5=AE=9E=E7=8E=B0?= =?UTF-8?q?=E5=81=87=E8=AE=BE=E5=A4=B4=E9=83=A8=E5=AD=97=E6=AE=B5=E5=90=8D?= =?UTF-8?q?=E7=A7=B0=E4=B8=8D=E9=87=8D=E5=A4=8D=EF=BC=8C=E5=9B=A0=E6=AD=A4?= =?UTF-8?q?=E5=9C=A8=E6=9E=84=E5=BB=BA=E5=85=B7=E6=9C=89=E5=90=8C=E5=90=8D?= =?UTF-8?q?=E7=A7=B0=E5=A4=B4=E9=83=A8=E5=AD=97=E6=AE=B5=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E5=90=8E=E8=AE=BE=E7=BD=AE=E7=9A=84=E5=80=BC=E4=BC=9A=E6=9B=BF?= =?UTF-8?q?=E6=8D=A2=E5=85=88=E8=AE=BE=E7=BD=AE=E7=9A=84=E5=80=BC=EF=BC=9B?= =?UTF-8?q?=20*=20=E7=8E=B0=E4=BF=AE=E6=AD=A3=EF=BC=8C=E6=9E=84=E5=BB=BA?= =?UTF-8?q?=E5=85=B7=E6=9C=89=E5=90=8C=E5=90=8D=E7=A7=B0=E5=A4=B4=E9=83=A8?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E6=97=B6=E4=B8=8D=E8=A6=86=E7=9B=96=E5=8E=9F?= =?UTF-8?q?=E6=9D=A5=E7=9A=84=E5=80=BC=EF=BC=8C=E8=80=8C=E6=98=AF=E5=9C=A8?= =?UTF-8?q?=E5=A4=B4=E9=83=A8=E8=BF=BD=E5=8A=A0=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/protocol/http/src/http_half.cpp | 55 +++++++++++--------------- 1 file changed, 24 insertions(+), 31 deletions(-) diff --git a/plugin/protocol/http/src/http_half.cpp b/plugin/protocol/http/src/http_half.cpp index 29048da..6a05f1a 100644 --- a/plugin/protocol/http/src/http_half.cpp +++ b/plugin/protocol/http/src/http_half.cpp @@ -517,41 +517,34 @@ int hf_ops_field_write(struct tfe_http_half * half, const struct http_field_name struct http_half_private * hf_private = to_hf_private(half); assert(hf_private->major == 0 || hf_private->major == 1); - struct http_header_private * __header_iter = NULL; - struct http_header_private * __header_found = NULL; - - TAILQ_FOREACH(__header_iter, &hf_private->header_list, next) + /* Add a k-v in the tail of the header list */ + if (value != NULL) { - if (http_field_name_compare(__header_iter->field, field) != 0) continue; - __header_found = __header_iter; - break; + struct http_header_private * new_header = ALLOC(struct http_header_private, 1); + new_header->field = http_field_name_duplicate(field); + new_header->value = tfe_strdup(value); + TAILQ_INSERT_TAIL(&hf_private->header_list, new_header, next); } - - /* Update the value */ - if (__header_found != NULL && value != NULL) - { - free(__header_found->value); - __header_found->value = tfe_strdup(value); - } - /* Delete the key and value */ - else if (__header_found != NULL && value == NULL) - { - TAILQ_REMOVE(&hf_private->header_list, __header_found, next); - free(__header_found->value); - free(__header_found); - } - /* Insert a new header k-v in the tail of the header list */ - else if (__header_found == NULL && value != NULL) - { - struct http_header_private * __header = ALLOC(struct http_header_private, 1); - __header->field = http_field_name_duplicate(field); - __header->value = tfe_strdup(value); - TAILQ_INSERT_TAIL(&hf_private->header_list, __header, next); - } - /* Nothing found, and delete nothing */ + /* Delete a value */ else { - return -1; + struct http_header_private * header_iter = NULL; + struct http_header_private * header_titer = NULL; + bool delete_success = false; + + TAILQ_FOREACH_SAFE(header_iter, &hf_private->header_list, next, header_titer) + { + if (http_field_name_compare(header_iter->field, field) != 0) + continue; + + TAILQ_REMOVE(&hf_private->header_list, header_iter, next); + http_field_name_destory(header_iter->field); + free(header_iter->value); + free(header_iter); + delete_success = true; + } + + return delete_success ? 0 : -ENOENT; } return 0;