88087146d46be6367104ae5535022e34aa997827 galt Mon Dec 9 17:10:42 2013 -0800 net.c dealing with FTP subtleties regarding url-encoding and the leading slash in the path requested diff --git src/lib/net.c src/lib/net.c index 3357381..8f850df 100644 --- src/lib/net.c +++ src/lib/net.c @@ -469,37 +469,52 @@ { *s = 0; tolowers(url); safecpy(parsed->protocol, sizeof(parsed->protocol), url); s += 3; } /* Split off file part. */ parsed->byteRangeStart = -1; /* default to no byte range specified */ parsed->byteRangeEnd = -1; u = strchr(s, '/'); if (u == NULL) strcpy(parsed->file, "/"); else { + parseByteRange(u, &parsed->byteRangeStart, &parsed->byteRangeEnd, TRUE); + if (sameWord(parsed->protocol,"http") || + sameWord(parsed->protocol,"https")) + { + // http servers expect the URL request to be URL-encoded already. /* need to encode spaces, but not ! other characters */ char *t=replaceChars(u," ","%20"); safecpy(parsed->file, sizeof(parsed->file), t); freeMem(t); - *u = 0; + } + + *u = 0; // terminate the host:port string + + if (sameWord(parsed->protocol,"ftp")) + { + ++u; // that first slash is not considered part of the ftp path + // decode now because the FTP server does NOT expect URL-encoding. + cgiDecode(u,parsed->file,strlen(u)); + } + } /* Split off user part */ v = strchr(s, '@'); if (v == NULL) { if (sameWord(parsed->protocol,"http") || sameWord(parsed->protocol,"https")) { strcpy(parsed->user, ""); strcpy(parsed->password, ""); } if (sameWord(parsed->protocol,"ftp")) { strcpy(parsed->user, "anonymous");