- return talloc_asprintf(url, "%s://%s%s", scheme->str,
- scheme->has_host ? url->host : "", url->path);
+ port = url->port ? talloc_asprintf(url, ":%s", url->port) : NULL;
+
+ if (scheme->has_host && addr_scheme(url->host) == AF_INET6)
+ str = talloc_asprintf(url, "%s://[%s]%s%s", scheme->str,
+ url->host, port ?: "", url->path);
+ else
+ str = talloc_asprintf(url, "%s://%s%s%s", scheme->str,
+ scheme->has_host ? url->host : "",
+ port ?: "", url->path);
+
+ talloc_free(port);
+ return str;