From e37b33abc6e2d4add946d9a2b1461ebd53751f16 Mon Sep 17 00:00:00 2001 From: mike Date: Thu, 30 Aug 2001 00:57:35 +0000 Subject: [PATCH] Add support for HTTP/1.1 name-based virtual hosts. Also, use asprintf(3) when creating the request string, as the length of a path is defined as unlimited by the standard and limiting the total request to 4K is awfully arbitrary. PR: 30054 Submitted by: Joseph Mallett MFC after: 8 days --- usr.bin/ftp/fetch.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/usr.bin/ftp/fetch.c b/usr.bin/ftp/fetch.c index f833f01f5a08..cce524d50f2b 100644 --- a/usr.bin/ftp/fetch.c +++ b/usr.bin/ftp/fetch.c @@ -104,7 +104,7 @@ url_get(origline, proxyenv) char *port; volatile int s; size_t len; - char c, *cp, *ep, *portnum, *path, buf[4096]; + char c, *cp, *ep, *http_buffer, *portnum, *path, buf[4096]; const char *savefile; char *line, *proxy, *host; volatile sig_t oldintr; @@ -276,20 +276,25 @@ url_get(origline, proxyenv) * Construct and send the request. We're expecting a return * status of "200". Proxy requests don't want leading /. */ - if (!proxy) + if (!proxy) { printf("Requesting %s\n", origline); - else + len = asprintf(&http_buffer, + "GET /%s HTTP/1.1\r\nHost: %s\r\nConnection: close\r\n\r\n", path, host); + } else { printf("Requesting %s (via %s)\n", origline, proxyenv); - len = snprintf(buf, sizeof(buf), "GET %s%s HTTP/1.0\r\n\r\n", - proxy ? "" : "/", path); - if (len < 0 || len >= sizeof(buf)) { + len = asprintf(&http_buffer, + "GET %s HTTP/1.0\r\n\r\n", path); + } + if (len < 0) { warnx("Failed to format HTTP request"); goto cleanup_url_get; } - if (write(s, buf, len) < len) { + if (write(s, http_buffer, len) < len) { warn("Writing HTTP request"); + free(http_buffer); goto cleanup_url_get; } + free(http_buffer); memset(buf, 0, sizeof(buf)); for (cp = buf; cp < buf + sizeof(buf); ) { if (read(s, cp, 1) != 1)