修正HTTP2构建新头部时处理多个具有相同名称头部字段的处理逻辑

This commit is contained in:
fengweihao
2019-08-22 14:10:37 +08:00
committed by 陆秋文
parent 3a33de4b7c
commit 0b77bc0fc8

View File

@@ -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;