summaryrefslogtreecommitdiff
path: root/plugin/protocol/http2/src/http2_stream.cpp
diff options
context:
space:
mode:
authorfengweihao <[email protected]>2019-08-22 14:10:37 +0800
committer陆秋文 <[email protected]>2019-08-26 10:12:14 +0800
commit0b77bc0fc87009d80a52336707de1339f9657e34 (patch)
tree68fd53f8c5b3ad6cb9d3e668e4e30997e6ebf2bd /plugin/protocol/http2/src/http2_stream.cpp
parent3a33de4b7cf71d2f88f1be5f60192d1541396386 (diff)
修正HTTP2构建新头部时处理多个具有相同名称头部字段的处理逻辑
Diffstat (limited to 'plugin/protocol/http2/src/http2_stream.cpp')
-rw-r--r--plugin/protocol/http2/src/http2_stream.cpp50
1 files 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;