0f6c4d09420dc8cb7ba66393ada79363687582ce
galt
  Tue May 17 18:25:51 2011 -0700
Adding support for preserving user:password in urls during redirection
diff --git src/lib/net.c src/lib/net.c
index 0d36230..7dd98fc 100644
--- src/lib/net.c
+++ src/lib/net.c
@@ -1463,41 +1463,50 @@
 	/* we have a new url to try */
 	++redirectCount;
 	if (redirectCount > 5)
 	    {
 	    warn("code 30x redirects: exceeded limit of 5 redirects, %s", newUrl);
 	    success = FALSE;
 	    }
 	else if (!startsWith("http://",newUrl) 
               && !startsWith("https://",newUrl))
 	    {
 	    warn("redirected to non-http(s): %s", newUrl);
 	    success = FALSE;
 	    }
 	else 
 	    {
-	    struct netParsedUrl npu;
+	    struct netParsedUrl npu, newNpu;
 	    /* Parse the old URL to make parts available for graft onto the redirected url. */
-	    /* This makes redirection work with byterange urls */
-	    /* If needed we can preserve the user and password from the old url in a similar way. */
+	    /* This makes redirection work with byterange urls and user:password@ */
 	    netParseUrl(url, &npu);
+	    netParseUrl(newUrl, &newNpu);
+	    boolean updated = FALSE;
 	    if (npu.byteRangeStart != -1)
 		{
-		struct netParsedUrl newNpu;
-		netParseUrl(newUrl, &newNpu);
 		newNpu.byteRangeStart = npu.byteRangeStart;
 		newNpu.byteRangeEnd = npu.byteRangeEnd;
+		updated = TRUE;
+		}
+	    if ((npu.user[0] != 0) && (newNpu.user[0] == 0))
+		{
+		safecpy(newNpu.user,     sizeof newNpu.user,     npu.user);
+		safecpy(newNpu.password, sizeof newNpu.password, npu.password);
+		updated = TRUE;
+		}
+	    if (updated)
+		{
 		freeMem(newUrl);
 		newUrl = urlFromNetParsedUrl(&newNpu);
 		}
 	    sd = netUrlOpen(newUrl);
 	    if (sd < 0)
 		{
 		warn("Couldn't open %s", newUrl);
 		success = FALSE;
 		}
 	    }
 	}
     if (!success)
 	{  /* failure after 0 to 5 redirects */
 	if (redirectCount > 0)
 	    freeMem(newUrl);