summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeikki Korpela <heko@cvs.openbsd.org>2001-10-03 18:49:40 +0000
committerHeikki Korpela <heko@cvs.openbsd.org>2001-10-03 18:49:40 +0000
commitef70809245ce3f463656106772b6b9cdbf5d0a51 (patch)
treef546df4a5bd9b8c530924cca84100de0630e2319
parenta438ea89538a15a71d394c7f69aa68505c91b71b (diff)
o Only send port number in the HTTP request 'Host: ' specification
if it is non-default (i.e., != 80) to circumvent bugs in some broken HTTP servers. naddy@ got hit by this with a port, lebel@ spotted the problem. o Print the HTTP request if debug (the ``-d'' flag) is specified. millert@ ok
-rw-r--r--usr.bin/ftp/fetch.c33
1 files changed, 25 insertions, 8 deletions
diff --git a/usr.bin/ftp/fetch.c b/usr.bin/ftp/fetch.c
index 333221c2a72..b61542768ae 100644
--- a/usr.bin/ftp/fetch.c
+++ b/usr.bin/ftp/fetch.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fetch.c,v 1.34 2001/06/23 22:48:44 millert Exp $ */
+/* $OpenBSD: fetch.c,v 1.35 2001/10/03 18:49:39 heko Exp $ */
/* $NetBSD: fetch.c,v 1.14 1997/08/18 10:20:20 lukem Exp $ */
/*-
@@ -38,7 +38,7 @@
*/
#ifndef lint
-static char rcsid[] = "$OpenBSD: fetch.c,v 1.34 2001/06/23 22:48:44 millert Exp $";
+static char rcsid[] = "$OpenBSD: fetch.c,v 1.35 2001/10/03 18:49:39 heko Exp $";
#endif /* not lint */
/*
@@ -362,17 +362,34 @@ again:
errx(1, "Can't allocate memory.");
if ((p = strchr(h, '%')) != NULL)
*p = '\0';
- snprintf(buf, sizeof(buf),
- "GET /%s HTTP/1.0\r\nHost: [%s]%s%s\r\n\r\n",
- path, h, port ? ":" : "", port ? port : "");
+ /*
+ * Send port number only if it's specified and does not equal
+ * 80. Some broken HTTP servers get confused if you explicitly
+ * send them the port number.
+ */
+ if (port && strcmp(port, "80") != 0)
+ snprintf(buf, sizeof(buf),
+ "GET /%s HTTP/1.0\r\nHost: [%s]:%s\r\n\r\n",
+ path, h, port);
+ else
+ snprintf(buf, sizeof(buf),
+ "GET /%s HTTP/1.0\r\nHost: [%s]\r\n\r\n",
+ path, h);
free(h);
} else {
- snprintf(buf, sizeof(buf),
- "GET /%s HTTP/1.0\r\nHost: %s%s%s\r\n\r\n",
- path, host, port ? ":" : "", port ? port : "");
+ if (port && strcmp(port, "80") != 0)
+ snprintf(buf, sizeof(buf),
+ "GET /%s HTTP/1.0\r\nHost: %s:%s\r\n\r\n",
+ path, host, port);
+ else
+ snprintf(buf, sizeof(buf),
+ "GET /%s HTTP/1.0\r\nHost: %s\r\n\r\n",
+ path, host);
}
}
len = strlen(buf);
+ if (debug)
+ fprintf(ttyout, "Sending request:\n%s", buf);
if (write(s, buf, len) < len) {
warn("Writing HTTP request");
goto cleanup_url_get;