summaryrefslogtreecommitdiffstats
path: root/usr.bin/ftp
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/ftp')
-rw-r--r--usr.bin/ftp/fetch.c19
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)
OpenPOWER on IntegriCloud