diff options
author | mike <mike@FreeBSD.org> | 2001-08-30 00:57:35 +0000 |
---|---|---|
committer | mike <mike@FreeBSD.org> | 2001-08-30 00:57:35 +0000 |
commit | e37b33abc6e2d4add946d9a2b1461ebd53751f16 (patch) | |
tree | ad64b2dc377aad3bb1823a48ab4250d5223c1695 /usr.bin | |
parent | 497cd6cff0719975c41e7feedabec8d1de90dbd0 (diff) | |
download | FreeBSD-src-e37b33abc6e2d4add946d9a2b1461ebd53751f16.zip FreeBSD-src-e37b33abc6e2d4add946d9a2b1461ebd53751f16.tar.gz |
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 <jmallett@xMach.org>
MFC after: 8 days
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/ftp/fetch.c | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/usr.bin/ftp/fetch.c b/usr.bin/ftp/fetch.c index f833f01..cce524d 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) |