diff options
| author | Garrett D'Amore <garrett@damore.org> | 2024-11-18 01:17:24 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2024-11-18 08:33:05 -0800 |
| commit | ca6cfe359fa55a5a7f4b6ae73500ffd98e6ee968 (patch) | |
| tree | d69a9af2e88c9bf5bc0d565bdd2ea975f2723d52 /src/supplemental/http/http_msg.c | |
| parent | e54e2b1a98abfdb75232a9b3218714ce34c9a34f (diff) | |
| download | nng-ca6cfe359fa55a5a7f4b6ae73500ffd98e6ee968.tar.gz nng-ca6cfe359fa55a5a7f4b6ae73500ffd98e6ee968.tar.bz2 nng-ca6cfe359fa55a5a7f4b6ae73500ffd98e6ee968.zip | |
URL refactor part 1.
This eliminates most (but not all) of the dynamic allocations
associated with URL objects. A number of convenience fields
on the URL are removed, but we are able to use common buffer
for most of the details.
Diffstat (limited to 'src/supplemental/http/http_msg.c')
| -rw-r--r-- | src/supplemental/http/http_msg.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/supplemental/http/http_msg.c b/src/supplemental/http/http_msg.c index 28c89ec7..a2ab218f 100644 --- a/src/supplemental/http/http_msg.c +++ b/src/supplemental/http/http_msg.c @@ -617,8 +617,13 @@ nni_http_req_alloc(nni_http_req **reqp, const nni_url *url) req->uri = NULL; if (url != NULL) { const char *host; + char host_buf[264]; // 256 + 8 for port int rv; - if ((req->uri = nni_strdup(url->u_requri)) == NULL) { + rv = nni_asprintf(&req->uri, "%s%s%s%s%s", url->u_path, + url->u_query ? "?" : "", url->u_query ? url->u_query : "", + url->u_fragment ? "#" : "", + url->u_fragment ? url->u_fragment : ""); + if (rv != 0) { NNI_FREE_STRUCT(req); return (NNG_ENOMEM); } @@ -628,7 +633,14 @@ nni_http_req_alloc(nni_http_req **reqp, const nni_url *url) if (nni_url_default_port(url->u_scheme) == url->u_port) { host = url->u_hostname; } else { - host = url->u_host; + if (strchr(url->u_hostname, ':')) { + snprintf(host_buf, sizeof(host_buf), "[%s]:%u", + url->u_hostname, url->u_port); + } else { + snprintf(host_buf, sizeof(host_buf), "%s:%u", + url->u_hostname, url->u_port); + } + host = host_buf; } if ((rv = nni_http_req_add_header(req, "Host", host)) != 0) { nni_http_req_free(req); |
