修正HTTP2构建新头部时处理多个具有相同名称头部字段的处理逻辑
This commit is contained in:
@@ -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_header *h2_header = &(half_private->header);
|
||||||
struct tfe_h2_field *h2_field=NULL,*peer_h2_field=NULL;
|
struct tfe_h2_field *h2_field=NULL,*peer_h2_field=NULL;
|
||||||
|
|
||||||
TAILQ_FOREACH(h2_field, &h2_header->h2_field_list, next)
|
if (value != NULL)
|
||||||
{
|
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
tfe_h2_header_add_field(h2_header, field, value, 1);
|
tfe_h2_header_add_field(h2_header, field, value, 1);
|
||||||
}
|
}
|
||||||
else
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -780,12 +773,14 @@ nghttp2_frame_submit_built_resp(struct tfe_h2_stream *h2_stream_info,
|
|||||||
snprintf(str_sz_evbuf_body, sizeof(str_sz_evbuf_body) - 1, "%lu", evbuffer_get_length(body->evbuf_body));
|
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);
|
tfe_http_field_write(&pangu_resp->half_public, &cont_field, str_sz_evbuf_body);
|
||||||
|
|
||||||
if (body->gzip != HTTP2_CONTENT_ENCODING_NONE)
|
if (body->gzip != HTTP2_CONTENT_ENCODING_NONE)
|
||||||
{
|
{
|
||||||
const static struct http_field_name encoding_field = {TFE_HTTP_CONT_ENCODING, NULL};
|
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);
|
tfe_http_field_write(&pangu_resp->half_public, &encoding_field, content_encoding);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -827,6 +822,7 @@ nghttp2_frame_submit_built_req(struct tfe_h2_stream *h2_stream_info,
|
|||||||
snprintf(str_sz_evbuf_body, sizeof(str_sz_evbuf_body) - 1, "%lu", evbuffer_get_length(body->evbuf_body));
|
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);
|
tfe_http_field_write(&plugin_built_req->half_public, &encoding_field, str_sz_evbuf_body);
|
||||||
|
|
||||||
nghttp2_data_provider data_prd;
|
nghttp2_data_provider data_prd;
|
||||||
|
|||||||
Reference in New Issue
Block a user