Skip to content

Commit

Permalink
http_common: updated to use the hash table in caseless mode
Browse files Browse the repository at this point in the history
Additionaly the explicitly set content-length was removed when
compressing the requests body was removed.

Signed-off-by: Leonardo Alminana <[email protected]>
  • Loading branch information
leonardo-albertovich authored and edsiper committed Jan 17, 2025
1 parent 1f5e5c7 commit 2a21514
Showing 1 changed file with 19 additions and 25 deletions.
44 changes: 19 additions & 25 deletions src/flb_http_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,16 @@ int flb_http_request_init(struct flb_http_request *request)
return -1;
}

flb_hash_table_set_case_sensitivity(request->headers, FLB_FALSE);

request->trailer_headers = flb_hash_table_create(FLB_HASH_TABLE_EVICT_NONE, 16, -1);

if (request->trailer_headers == NULL) {
return -1;
}

flb_hash_table_set_case_sensitivity(request->trailer_headers, FLB_FALSE);

return 0;
}

Expand Down Expand Up @@ -267,7 +271,7 @@ int flb_http_request_set_header(struct flb_http_request *request,
}

result = flb_hash_table_add(request->headers,
(const char *) lowercase_name,
(const char *) name,
name_length,
(void *) value,
value_length);
Expand All @@ -284,20 +288,10 @@ int flb_http_request_set_header(struct flb_http_request *request,
int flb_http_request_unset_header(struct flb_http_request *request,
char *name)
{
char *lowercase_name;
int result;

lowercase_name = flb_http_server_convert_string_to_lowercase(
name, strlen(name));

if (lowercase_name == NULL) {
return -1;
}
int result;

result = flb_hash_table_del(request->headers,
(const char *) lowercase_name);

flb_free(lowercase_name);
(const char *) name);

if (result == -1) {
return -1;
Expand Down Expand Up @@ -376,13 +370,9 @@ int flb_http_request_compress_body(
output_size);

flb_http_request_set_header(request,
"content-encoding", 0,
"Content-Encoding", 0,
content_encoding_header_value, 0);

flb_http_request_set_header(request,
"content-length", 0,
new_content_length, 0);

request->content_length = output_size;
}

Expand All @@ -407,7 +397,7 @@ int flb_http_request_uncompress_body(

content_encoding_header_value = flb_http_request_get_header(
request,
"content-encoding");
"Content-Encoding");

if (content_encoding_header_value == NULL) {
return 0;
Expand Down Expand Up @@ -462,9 +452,9 @@ int flb_http_request_uncompress_body(
"%zu",
output_size);

flb_http_request_unset_header(request, "content-encoding");
flb_http_request_unset_header(request, "Content-Encoding");
flb_http_request_set_header(request,
"content-length", 0,
"Content-Length", 0,
new_content_length, 0);

request->content_length = output_size;
Expand Down Expand Up @@ -739,7 +729,7 @@ int flb_http_request_set_content_encoding(struct flb_http_request *request,
char *encoding)
{
return flb_http_request_set_header(request,
"content-encoding", 0,
"Content-Encoding", 0,
encoding, 0);

}
Expand Down Expand Up @@ -840,6 +830,8 @@ int flb_http_response_init(struct flb_http_response *response)
return -1;
}

flb_hash_table_set_case_sensitivity(response->headers, FLB_FALSE);

response->trailer_headers = flb_hash_table_create(FLB_HASH_TABLE_EVICT_NONE, 16, -1);

if (response->trailer_headers == NULL) {
Expand All @@ -848,6 +840,8 @@ int flb_http_response_init(struct flb_http_response *response)
return -1;
}

flb_hash_table_set_case_sensitivity(response->trailer_headers, FLB_FALSE);

return 0;
}

Expand Down Expand Up @@ -1321,10 +1315,10 @@ int flb_http_response_uncompress_body(
"%zu",
output_size);

flb_http_response_unset_header(response, "content-encoding");
flb_http_response_unset_header(response, "Content-Encoding");
flb_http_response_set_header(response,
"content-length", 0,
new_content_length, 0);
"Content-Length", 0,
new_content_length, 0);

response->content_length = output_size;
}
Expand Down

0 comments on commit 2a21514

Please sign in to comment.