mirror of
https://github.com/espressif/esp-idf
synced 2025-03-09 09:09:10 -04:00
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
This commit is contained in:
commit
e2fc36349a
@ -703,10 +703,13 @@ static char *_get_host_header(char *host, int port)
|
||||
{
|
||||
int err = 0;
|
||||
char *host_name;
|
||||
assert(host != NULL);
|
||||
// Check if host is an IPv6 address literal that needs square brackets according to RFC3986
|
||||
bool is_ipv6 = (host[0] != '[' && strchr(host, ':') != NULL);
|
||||
if (port != DEFAULT_HTTP_PORT && port != DEFAULT_HTTPS_PORT) {
|
||||
err = asprintf(&host_name, "%s:%d", host, port);
|
||||
err = asprintf(&host_name, is_ipv6 ? "[%s]:%d" : "%s:%d", host, port);
|
||||
} else {
|
||||
err = asprintf(&host_name, "%s", host);
|
||||
err = asprintf(&host_name, is_ipv6 ? "[%s]" : "%s", host);
|
||||
}
|
||||
if (err == -1) {
|
||||
return NULL;
|
||||
|
Loading…
x
Reference in New Issue
Block a user