From 3f4b7cbd90bff89d94696feecc6f46933ae50010 Mon Sep 17 00:00:00 2001 From: Lu Qiuwen Date: Fri, 28 Sep 2018 19:52:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=9E=84=E5=BB=BAHTTP?= =?UTF-8?q?=E5=BA=94=E7=AD=94=E6=97=B6=EF=BC=8C=E5=90=8C=E6=97=B6=E5=A1=AB?= =?UTF-8?q?=E5=86=99Content-Length=E5=92=8CTransfer-Encoding:=20Chunk?= =?UTF-8?q?=E6=8A=A5=E5=A4=B4=EF=BC=8C=E5=AF=BC=E8=87=B4=E6=B5=8F=E8=A7=88?= =?UTF-8?q?=E5=99=A8=E8=A7=A3=E6=9E=90=E5=A4=B1=E8=B4=A5=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=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 | 31 +++++++++++++++++++------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/plugin/protocol/http/src/http_half.cpp b/plugin/protocol/http/src/http_half.cpp index 2d51271..2a6c151 100644 --- a/plugin/protocol/http/src/http_half.cpp +++ b/plugin/protocol/http/src/http_half.cpp @@ -187,7 +187,7 @@ void __hf_public_req_fill_from_private(struct http_half_private * hf_private, st /* Accept-Encoding */ const static struct http_field_name __accept_encoding_name = {TFE_HTTP_ACCEPT_ENCODING, NULL}; - const char * __str_accept_encoding = tfe_http_field_read(hf_public, &__accept_encoding_name); + const char * __str_accept_encoding = tfe_http_field_read(hf_public, &__accept_encoding_name); if (__str_accept_encoding != NULL) { hf_private->accept_content_encoding = __hf_content_encoding_parse(__str_accept_encoding); @@ -471,21 +471,32 @@ int hf_ops_field_write(struct tfe_http_half * half, const struct http_field_name __header_found = __header_iter; break; } - /* Found a header, update a value, - * or insert a new header k-v in the tail of the header list */ - - if(__header_found != NULL) + /* Update the value */ + if(__header_found != NULL && value != NULL) { - if (__header_found->value != NULL) free(__header_found->value); + free(__header_found->value); __header_found->value = tfe_strdup(value); } - else + /* 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 */ + else + { + return -1; + } return 0; } @@ -537,7 +548,7 @@ int hf_ops_append_body(struct tfe_http_half * half, char * buff, size_t size, in if (hf_private->cv_compress_object) { ret = hf_content_compress_write(hf_private->cv_compress_object, - (const unsigned char *)buff, size, hf_private->evbuf_body, 0); + (const unsigned char *) buff, size, hf_private->evbuf_body, 0); } else { @@ -841,6 +852,10 @@ void hf_private_construct(struct http_half_private * hf_private) const static struct http_field_name __cont_encoding_length_name = {TFE_HTTP_CONT_LENGTH, NULL}; tfe_http_field_write(hf_public, &__cont_encoding_length_name, str_sz_evbuf_body); + + /* If origin is chunked, now delete chunked tag */ + const static struct http_field_name __cont_transfer_encoding_name = {TFE_HTTP_TRANSFER_ENCODING, NULL}; + tfe_http_field_write(hf_public, &__cont_transfer_encoding_name, NULL); } /* HTTP Request/Response first line */