Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/flb_http_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,7 @@ static int add_host_and_content_length(struct flb_http_client *c)
char *zone_id;
char addr_buf[INET6_ADDRSTRLEN];
int is_ipv6 = 0;
int is_http_default_port;
int is_https_default_port;
const char *host_for_header;

Expand All @@ -653,13 +654,16 @@ static int add_host_and_content_length(struct flb_http_client *c)
/* Check if connection uses TLS and port is 443 (HTTPS default) */
is_https_default_port = flb_stream_get_flag_status(&u->base, FLB_IO_TLS) && out_port == 443;

if (is_https_default_port) {
/* Check if connection does not use TLS and port is 80 (HTTP default) */
is_http_default_port = !flb_stream_get_flag_status(&u->base, FLB_IO_TLS) && out_port == 80;

if (is_https_default_port || is_http_default_port) {
if (is_ipv6) {
/* IPv6 address needs brackets for RFC compliance */
tmp = flb_sds_printf(&host, "[%s]", host_for_header);
}
else {
/* HTTPS on default port 443 - omit port from Host header */
/* HTTP/HTTPS on default ports (80/443) - omit port from Host header */
tmp = flb_sds_copy(host, out_host, strlen(out_host));
}
}
Expand Down
16 changes: 11 additions & 5 deletions tests/internal/http_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ void test_http_add_get_header()
struct flb_http_client *c;
flb_sds_t ret_str;
char *ua = "Fluent-Bit";
char *host = "127.0.0.1:80";
char *host = "127.0.0.1:8080";
int ret;

ctx = test_ctx_create();
Expand All @@ -154,7 +154,7 @@ void test_http_add_get_header()

/* Create HTTP client instance */
c = flb_http_client(ctx->u_conn, FLB_HTTP_GET, "/", NULL, 0,
"127.0.0.1", 80, NULL, 0);
"127.0.0.1", 8080, NULL, 0);
if(!TEST_CHECK(c != NULL)) {
TEST_MSG("flb_http_client failed");
test_ctx_destroy(ctx);
Expand Down Expand Up @@ -245,7 +245,7 @@ void test_http_strip_port_from_host()
struct test_ctx *ctx;
struct flb_http_client *c;
flb_sds_t ret_str;
char *host_port = "127.0.0.1:80";
char *host_port = "127.0.0.1:8080";
char *host = "127.0.0.1";
int ret;

Expand All @@ -256,7 +256,7 @@ void test_http_strip_port_from_host()

/* Create HTTP client instance */
c = flb_http_client(ctx->u_conn, FLB_HTTP_GET, "/", NULL, 0,
"127.0.0.1", 80, NULL, 0);
"127.0.0.1", 8080, NULL, 0);
if(!TEST_CHECK(c != NULL)) {
TEST_MSG("flb_http_client failed");
test_ctx_destroy(ctx);
Expand Down Expand Up @@ -593,7 +593,12 @@ void test_ipv6_formats_host_header()

void test_http_port_80_host_header()
{
test_host_header_format("example.com", 80, "example.com:80");
test_host_header_format("example.com", 80, "example.com");
}

void test_http_non_standard_port_host_header()
{
test_host_header_format("example.com", 8080, "example.com:8080");
}

void test_port_443_without_tls_host_header()
Expand Down Expand Up @@ -653,6 +658,7 @@ TEST_LIST = {
{ "https_default_port_host_header", test_https_default_port_host_header},
{ "ipv6_formats_host_header", test_ipv6_formats_host_header},
{ "http_port_80_host_header", test_http_port_80_host_header},
{ "http_non_standard_port_host_header", test_http_non_standard_port_host_header},
{ "port_443_without_tls_host_header", test_port_443_without_tls_host_header},
{ "ipv6_zone_id_host_header", test_ipv6_zone_id_host_header},
{ "https_non_standard_port_host_header", test_https_non_standard_port_host_header},
Expand Down