mirror of
https://github.com/espressif/esp-idf
synced 2025-03-09 17:19:09 -04:00
fix(esp_http_client): Fix host header for IPv6 address literal
An IPv6 IP that occurs in the 'Host:' header of an HTTP request must be enclosed in square brackets (RFC3986 section 3.2.2). Searches for ':' in the host string to efficiently determine if the host is an IPv6 IP address.
This commit is contained in:
parent
0d6099ec53
commit
f31a0f7f61
@ -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