+
+ if (url_str) {
+ size_t len;
+
+ *url_str = emalloc(HTTP_URL_MAXLEN + 1);
+
+ **url_str = '\0';
+ strlcat(*url_str, url->scheme, HTTP_URL_MAXLEN);
+ strlcat(*url_str, "://", HTTP_URL_MAXLEN);
+
+ if (url->user && *url->user) {
+ strlcat(*url_str, url->user, HTTP_URL_MAXLEN);
+ if (url->pass && *url->pass) {
+ strlcat(*url_str, ":", HTTP_URL_MAXLEN);
+ strlcat(*url_str, url->pass, HTTP_URL_MAXLEN);
+ }
+ strlcat(*url_str, "@", HTTP_URL_MAXLEN);
+ }
+
+ strlcat(*url_str, url->host, HTTP_URL_MAXLEN);
+
+ if (url->port) {
+ char port_str[6] = {0};
+
+ snprintf(port_str, 5, "%d", (int) url->port);
+ strlcat(*url_str, ":", HTTP_URL_MAXLEN);
+ strlcat(*url_str, port_str, HTTP_URL_MAXLEN);
+ }
+
+ if (*url->path != '/') {
+ strlcat(*url_str, "/", HTTP_URL_MAXLEN);
+ }
+ strlcat(*url_str, url->path, HTTP_URL_MAXLEN);
+
+ if (url->query && *url->query) {
+ strlcat(*url_str, "?", HTTP_URL_MAXLEN);
+ strlcat(*url_str, url->query, HTTP_URL_MAXLEN);
+ }
+
+ if (url->fragment && *url->fragment) {
+ strlcat(*url_str, "#", HTTP_URL_MAXLEN);
+ strlcat(*url_str, url->fragment, HTTP_URL_MAXLEN);
+ }
+
+ if (HTTP_URL_MAXLEN == (len = strlen(*url_str))) {
+ http_error(HE_NOTICE, HTTP_E_URL, "Length of URL exceeds HTTP_URL_MAXLEN");
+ }
+ if (url_len) {
+ *url_len = len;
+ }