From e6eb32918765399a8eb5b6ef797229cc1cb453b6 Mon Sep 17 00:00:00 2001 From: Atikur Rahman Chitholian Date: Tue, 23 Dec 2025 12:55:46 +0600 Subject: [PATCH] Add non-default port to the HTTP Host header during webhook call --- telegram-bot-api/WebhookActor.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/telegram-bot-api/WebhookActor.cpp b/telegram-bot-api/WebhookActor.cpp index 46898e320..fb3e78e86 100644 --- a/telegram-bot-api/WebhookActor.cpp +++ b/telegram-bot-api/WebhookActor.cpp @@ -552,7 +552,14 @@ td::Status WebhookActor::send_update() { td::HttpHeaderCreator hc; hc.init_post(url_.query_); - hc.add_header("Host", url_.host_); + + auto hostHeaderValue = url_.host_; + // Append :port to the host header if a non-default port was specified. + if ((url_.protocol_ == td::HttpUrl::Protocol::Https && url_.port_ != 443) || (url_.protocol_ == td::HttpUrl::Protocol::Http && url_.port_ != 80)) { + hostHeaderValue += ":" + std::to_string(url_.port_); + } + + hc.add_header("Host", hostHeaderValue); if (!url_.userinfo_.empty()) { hc.add_header("Authorization", PSLICE() << "Basic " << td::base64_encode(url_.userinfo_)); }