Subject: Re: bin/15415: ftp(1) would fail to fetch using HTTP.
To: None <itojun@iijlab.net>
From: Takahiro Kambe <taca@sky.yamashina.kyoto.jp>
List: netbsd-bugs
Date: 01/30/2002 12:26:28
In message <18703.1012357004@itojun.org>
	on Wed, 30 Jan 2002 11:16:44 +0900,
	itojun@iijlab.net wrote:
> >> you're missing the ':', it seems...
> >Thanks, you're absolutely right.
> 
> 	the patch looks incorect.  if port number is not 80, "fin" ends
> 	up like ":1234", not "Host: address:1234".
I should attach my first simple fix.

--- usr.bin/ftp/fetch.c.orig	Fri Dec 28 10:07:27 2001
+++ usr.bin/ftp/fetch.c	Wed Jan 30 12:21:21 2002
@@ -730,10 +730,21 @@
 				    (p = strchr(h, '%')) != NULL) {
 					*p = '\0';
 				}
-				fprintf(fin, "Host: [%s]:%d\r\n", h, portnum);
+				if (portnum == HTTP_PORT) {
+					fprintf(fin, "Host: [%s]\r\n", h);
+				} else {
+					fprintf(fin, "Host: [%s]:%d\r\n", h,
+						portnum);
+				}
 				free(h);
-			} else
-				fprintf(fin, "Host: %s:%d\r\n", host, portnum);
+			} else {
+				if (portnum == HTTP_PORT) {
+					fprintf(fin, "Host: %s\r\n", host);
+				} else {
+					fprintf(fin, "Host: %s:%d\r\n", host,
+						portnum);
+				}
+			}
 			fprintf(fin, "Accept: */*\r\n");
 			fprintf(fin, "Connection: close\r\n");
 			if (restart_point) {