From ef70809245ce3f463656106772b6b9cdbf5d0a51 Mon Sep 17 00:00:00 2001 From: Heikki Korpela Date: Wed, 3 Oct 2001 18:49:40 +0000 Subject: 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 --- usr.bin/ftp/fetch.c | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) (limited to 'usr.bin') 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; -- cgit v1.2.3