From 3fdfd7033f1473dcf6f3fd1812035be9ae85a02b Mon Sep 17 00:00:00 2001 From: Katriel Traum Date: Tue, 20 Jan 2026 18:00:13 +0000 Subject: [PATCH 1/3] http_client: omit default port in Host header for HTTP/80 This patch modifies the HTTP client to omit the port number from the Host header when using standard HTTP (port 80), similar to how HTTPS (port 443) is already handled. This ensures compatibility with servers that reject Host headers containing the default port, such as the GCP Metadata Server concealment proxy in certain environments (e.g. Cloud Run). Signed-off-by: Katriel Traum --- src/flb_http_client.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/flb_http_client.c b/src/flb_http_client.c index e1bd048a7ec..a6d4ce7dd16 100644 --- a/src/flb_http_client.c +++ b/src/flb_http_client.c @@ -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; @@ -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)); } } From fbcd7bb4e9d435c4d6a0fcadf82b947a11a5144a Mon Sep 17 00:00:00 2001 From: Katriel Traum Date: Tue, 20 Jan 2026 18:34:57 +0000 Subject: [PATCH 2/3] http_client: omit default port in Host header for HTTP/80 - test Implement tests to check new use cases Signed-off-by: Katriel Traum --- tests/internal/http_client.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/internal/http_client.c b/tests/internal/http_client.c index 6e04150c201..b147e5fdb21 100644 --- a/tests/internal/http_client.c +++ b/tests/internal/http_client.c @@ -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() @@ -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}, From 68401e3cfdf0acb822da83f8de8934a27b54f40e Mon Sep 17 00:00:00 2001 From: Katriel Traum Date: Tue, 20 Jan 2026 18:59:46 +0000 Subject: [PATCH 3/3] http_client: omit default port in Host header for HTTP/80 - test Fix additional tests affected by fix: test_http_add_get_header and test_http_strip_port_from_host Signed-off-by: Katriel Traum --- tests/internal/http_client.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/internal/http_client.c b/tests/internal/http_client.c index b147e5fdb21..0c89b02a843 100644 --- a/tests/internal/http_client.c +++ b/tests/internal/http_client.c @@ -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(); @@ -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); @@ -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; @@ -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);