90d648fa2085f370a74fcf648fc7060efde39640
kent
  Sun Mar 31 15:57:03 2013 -0700
Added netUrlMustOpenPastHeader
diff --git src/lib/net.c src/lib/net.c
index 2a228d7..47d55c3 100644
--- src/lib/net.c
+++ src/lib/net.c
@@ -1387,30 +1387,35 @@
 	    {
 	    mustUseProxyAuth = TRUE;
 	    }
 	else if (byteRangeUsed 
 	    /* hack for Apache bug 2.2.20 and 2.2.21 2011-10-21 should be OK to remove after one year. */
 		&& !(sameString(code, "200") && byteRangeStart == 0 && byteRangeEnd == -1))  
 	    {
 	    if (!sameString(code, "206"))
 		{
 		if (sameString(code, "200"))
 		    warn("Byte-range request was ignored by server. ");
 		warn("Expected Partial Content 206. %s: %s %s", url, code, line);
 		return FALSE;
 		}
 	    }
+	else if (sameString(code, "404"))
+	    {
+	    warn("404 file not found on %s", url);
+	    return FALSE;
+	    }
 	else if (!sameString(code, "200"))
 	    {
 	    warn("Expected 200 %s: %s %s", url, code, line);
 	    return FALSE;
 	    }
 	line = buf;  /* restore it */
 	}
     headerName = line;
     sep = strchr(line,':');
     if (sep)
 	{
 	*sep = 0;
 	headerVal = skipLeadingSpaces(++sep);
 	}
     else
@@ -1607,30 +1612,53 @@
     if (isCompressed)
 	{
 	lf = lineFileDecompressFd(url, TRUE, sd);
            /* url needed only for compress type determination */
 	}
     else
 	{
 	lf = lineFileAttach(url, TRUE, sd);
 	}
     if (newUrl) 
 	freeMem(newUrl); 
     return lf;
     }
 }
 
+int netUrlMustOpenPastHeader(char *url)
+/* Get socket descriptor for URL.  Process header, handling any forwarding and
+ * the like.  Do errAbort if there's a problem, which includes anything but a 200
+ * return from http after forwarding. */
+{
+int sd = netUrlOpen(url);
+if (sd < 0)
+    noWarnAbort();
+int newSd = 0;
+if (startsWith("http://",url) || startsWith("https://",url))
+    {  
+    char *newUrl = NULL;
+    if (!netSkipHttpHeaderLinesHandlingRedirect(sd, url, &newSd, &newUrl))
+	noWarnAbort();
+    if (newUrl != NULL)
+	{
+	sd = newSd;
+	freeMem(newUrl); 
+	}
+    }
+return sd;
+}
+
 struct lineFile *netLineFileSilentOpen(char *url)
 /* Open a lineFile on a URL.  Just return NULL without any user
  * visible warning message if there's a problem. */
 {
 pushSilentWarnHandler();
 struct lineFile *lf = netLineFileMayOpen(url);
 popWarnHandler();
 return lf;
 }
 
 char *netReadTextFileIfExists(char *url)
 /* Read entire URL and return it as a string.  URL should be text (embedded zeros will be
  * interpreted as end of string).  If the url doesn't exist or has other problems,
  * returns NULL. */
 {