Skip to content

Commit e2fc363

Browse files
committed
Merge branch 'contrib/github_pr_15388' into 'master'
fix(esp_http_client): Fix host header for IPv6 address literal (GitHub PR) Closes IDFGH-14640 See merge request espressif/esp-idf!37035
2 parents c9dff55 + f31a0f7 commit e2fc363

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

components/esp_http_client/esp_http_client.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -703,10 +703,13 @@ static char *_get_host_header(char *host, int port)
703703
{
704704
int err = 0;
705705
char *host_name;
706+
assert(host != NULL);
707+
// Check if host is an IPv6 address literal that needs square brackets according to RFC3986
708+
bool is_ipv6 = (host[0] != '[' && strchr(host, ':') != NULL);
706709
if (port != DEFAULT_HTTP_PORT && port != DEFAULT_HTTPS_PORT) {
707-
err = asprintf(&host_name, "%s:%d", host, port);
710+
err = asprintf(&host_name, is_ipv6 ? "[%s]:%d" : "%s:%d", host, port);
708711
} else {
709-
err = asprintf(&host_name, "%s", host);
712+
err = asprintf(&host_name, is_ipv6 ? "[%s]" : "%s", host);
710713
}
711714
if (err == -1) {
712715
return NULL;

0 commit comments

Comments
 (0)