Subject: bin/3891: http support in ftp(1) needs "Content-length" header
To: None <gnats-bugs@gnats.netbsd.org>
From: Krister Walfridsson <cato@ulysses.df.lth.se>
List: netbsd-bugs
Date: 07/20/1997 10:20:33
>Number:         3891
>Category:       bin
>Synopsis:       http support in ftp(1) needs "Content-length" header
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Jul 20 01:35:01 1997
>Last-Modified:
>Originator:     Krister Walfridsson
>Organization:
	
>Release:        NetBSD-current 19 Jul 1997
>Environment:
	
System: NetBSD ulysses 1.2G NetBSD 1.2G (KWA) #0: Sun Jul 13 16:33:57 MEST 1997 cato@ulysses:/usr/src/sys/arch/sparc/compile/KWA sparc


>Description:
ftp(1) usually refuses to fetch my URLs with http, since it needs a
"Content-length" header to be satisfied, but the servers aren't required
to send that header. ftp(1) doesn't really need the length either, since
it's used only for the progress bar.

One other bug in http support is that the request line should end with
CRLF


>How-To-Repeat:
bash$ ftp http://www.lesstif.org/index.html
Requesting http://www.lesstif.org/index.html
ftp: Improper response from www.lesstif.org

>Fix:
--- fetch.bak   Sun Jun 29 13:25:07 1997
+++ fetch.c     Sun Jul 20 09:25:48 1997
@@ -219,7 +219,7 @@
                printf("Requesting %s\n", origline);
        else
                printf("Requesting %s (via %s)\n", origline, proxyenv);
-       snprintf(buf, sizeof(buf), "GET %s%s HTTP/1.0\n\n",
+       snprintf(buf, sizeof(buf), "GET %s%s HTTP/1.0\r\n\r\n",
            proxy ? "" : "/", path);
        buflen = strlen(buf);
        if (write(s, buf, buflen) < buflen) {
@@ -271,17 +271,18 @@
                    strncasecmp(cp, CONTENTLEN, sizeof(CONTENTLEN) - 1) == 0)
                        break;
        }
-       if (*cp == '\0')
-               goto improper;
-       cp += sizeof(CONTENTLEN) - 1;
-       cp2 = strchr(cp, '\n');
-       if (cp2 == NULL)
-               goto improper;
-       else
-               *cp2 = '\0';
-       filesize = atoi(cp);
-       if (filesize < 1)
-               goto improper;
+       if (*cp != '\0') {
+               cp += sizeof(CONTENTLEN) - 1;
+               cp2 = strchr(cp, '\n');
+               if (cp2 == NULL)
+                       goto improper;
+               else
+                       *cp2 = '\0';
+               filesize = atoi(cp);
+               if (filesize < 1)
+                       goto improper;
+       } else
+               filesize = -1;
 
        /* Open the output file. */
        out = open(savefile, O_CREAT | O_WRONLY | O_TRUNC, 0666);

>Audit-Trail:
>Unformatted: