From tim@robbins.dropbear.id.au  Thu Dec 27 03:06:51 2001
Return-Path: <tim@robbins.dropbear.id.au>
Received: from raven.robbins.dropbear.id.au (060.c.001.mel.iprimus.net.au [203.134.131.60])
	by hub.freebsd.org (Postfix) with ESMTP id 5B27C37B417
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 27 Dec 2001 03:06:47 -0800 (PST)
Received: (from tim@localhost)
	by raven.robbins.dropbear.id.au (8.11.6/8.11.6) id fBRB6Vh43939;
	Thu, 27 Dec 2001 22:06:31 +1100 (EST)
	(envelope-from tim)
Message-Id: <200112271106.fBRB6Vh43939@raven.robbins.dropbear.id.au>
Date: Thu, 27 Dec 2001 22:06:31 +1100 (EST)
From: "Tim J. Robbins" <tim@robbins.dropbear.id.au>
Reply-To: "Tim J. Robbins" <tim@robbins.dropbear.id.au>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: ftp(1) fails to fetch files via HTTP from name-based vhost
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         33237
>Category:       bin
>Synopsis:       ftp(1) fails to fetch files via HTTP from name-based vhost
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    mike
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Thu Dec 27 03:10:01 PST 2001
>Closed-Date:    Thu Jan 3 04:39:36 PST 2002
>Last-Modified:  Thu Jan 03 04:41:50 PST 2002
>Originator:     Tim J. Robbins
>Release:        FreeBSD 4.4-STABLE i386
>Organization:
>Environment:
System: FreeBSD raven.robbins.dropbear.id.au 4.4-STABLE FreeBSD 4.4-STABLE #1: Thu Dec 20 19:34:48 EST 2001 root@raven.robbins.dropbear.id.au:/usr/obj/usr/src/sys/RAVEN i386


	
>Description:
ftp(1) does not send a HTTP Host: header with requests, which causes 404
Not Found errors, or the wrong page to be retrieved when name-based
virtual hosts are used.

It's worth noting that the sourceforge download server uses name-based
virtual hosts, so this could break a fair few downloads.

fetch doesn't have this same problem, only ftp.

>How-To-Repeat:

ftp(1) from -STABLE:

$ ftp.old -v http://www.phenoelit.de/irpas/irpas_0.9.tar.gz
Requesting http://www.phenoelit.de/irpas/irpas_0.9.tar.gz
ftp.old: Error retrieving file: 404 Not Found

After applying patch below:

$ ftp.new -v http://www.phenoelit.de/irpas/irpas_0.9.tar.gz
Requesting http://www.phenoelit.de/irpas/irpas_0.9.tar.gz
100% |**************************************************|   178 KB    00:00 ETA
Successfully retrieved file.

>Fix:
Send a Host: header containing the host portion from the URL.

--- fetch.c.old	Thu Dec 27 18:27:46 2001
+++ fetch.c	Thu Dec 27 18:29:05 2001
@@ -280,8 +280,8 @@
 		printf("Requesting %s\n", origline);
 	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);
+	len = snprintf(buf, sizeof(buf), "GET %s%s HTTP/1.0\r\nHost: %s\r\n\r\n",
+	    proxy ? "" : "/", path, host);
 	if (write(s, buf, len) < len) {
 		warn("Writing HTTP request");
 		goto cleanup_url_get;
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->mike 
Responsible-Changed-By: roam 
Responsible-Changed-When: Thu Dec 27 03:38:59 PST 2001 
Responsible-Changed-Why:  

Mike Barcroft seems to deal with 30054, he would know what to do 
with this one, too. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=33237 

From: carl@slackerbsd.org
To: "Tim J. Robbins" <tim@robbins.dropbear.id.au>
Cc: FreeBSD-gnats-submit@freebsd.org
Subject: Re: bin/33237: ftp(1) fails to fetch files via HTTP from name-based vhost
Date: Thu, 27 Dec 2001 06:37:15 -0500

 On Thu, Dec 27, 2001 at 10:06:31PM +1100, Tim J. Robbins wrote:
 > >Number:         33237
 > >Category:       bin
 > >Synopsis:       ftp(1) fails to fetch files via HTTP from name-based vhost
 > >Confidential:   no
 > >Severity:       non-critical
 > >Priority:       medium
 > >Responsible:    freebsd-bugs
 > >State:          open
 > >Quarter:        
 > >Keywords:       
 > >Date-Required:
 > >Class:          change-request
 > >Submitter-Id:   current-users
 > >Arrival-Date:   Thu Dec 27 03:10:01 PST 2001
 > >Closed-Date:
 > >Last-Modified:
 > >Originator:     Tim J. Robbins
 > >Release:        FreeBSD 4.4-STABLE i386
 > >Organization:
 > >Environment:
 > System: FreeBSD raven.robbins.dropbear.id.au 4.4-STABLE FreeBSD 4.4-STABLE #1: Thu Dec 20 19:34:48 EST 2001 root@raven.robbins.dropbear.id.au:/usr/obj/usr/src/sys/RAVEN i386
 > 
 > 
 > 	
 > >Description:
 > ftp(1) does not send a HTTP Host: header with requests, which causes 404
 > Not Found errors, or the wrong page to be retrieved when name-based
 > virtual hosts are used.
 > 
 > It's worth noting that the sourceforge download server uses name-based
 > virtual hosts, so this could break a fair few downloads.
 > 
 > fetch doesn't have this same problem, only ftp.
 > 
 > >How-To-Repeat:
 > 
 > ftp(1) from -STABLE:
 > 
 > $ ftp.old -v http://www.phenoelit.de/irpas/irpas_0.9.tar.gz
 > Requesting http://www.phenoelit.de/irpas/irpas_0.9.tar.gz
 > ftp.old: Error retrieving file: 404 Not Found
 > 
 > After applying patch below:
 > 
 > $ ftp.new -v http://www.phenoelit.de/irpas/irpas_0.9.tar.gz
 > Requesting http://www.phenoelit.de/irpas/irpas_0.9.tar.gz
 > 100% |**************************************************|   178 KB    00:00 ETA
 > Successfully retrieved file.
 > 
 > >Fix:
 > Send a Host: header containing the host portion from the URL.
 > 
 > --- fetch.c.old	Thu Dec 27 18:27:46 2001
 > +++ fetch.c	Thu Dec 27 18:29:05 2001
 > @@ -280,8 +280,8 @@
 >  		printf("Requesting %s\n", origline);
 >  	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);
 > +	len = snprintf(buf, sizeof(buf), "GET %s%s HTTP/1.0\r\nHost: %s\r\n\r\n",
 > +	    proxy ? "" : "/", path, host);
 >  	if (write(s, buf, len) < len) {
 >  		warn("Writing HTTP request");
 >  		goto cleanup_url_get;
 
 http://www.freebsd.org/cgi/query-pr.cgi?pr=bin/30054
 -- 
 Carl Schmidt
State-Changed-From-To: open->closed 
State-Changed-By: joe 
State-Changed-When: Thu Jan 3 04:39:36 PST 2002 
State-Changed-Why:  
We have a new verson of ftp in -current which will be MFC'd once a 
few compatibility issues are sorted out.  For now you can use fetch(1) 
instead of ftp as that supports http1.1 transfers. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=33237 
>Unformatted:
