56ea590fbda950add4188132d8e3fefe858a9098 galt Wed Feb 9 16:05:19 2011 -0800 adding detection of incorrect 200 response when expecting 206 partial content, should help detect earlier and explain the problem to users diff --git src/lib/net.c src/lib/net.c index 30eef80..54bb60c 100644 --- src/lib/net.c +++ src/lib/net.c @@ -1036,30 +1036,31 @@ * e.g. can pass it to the pipes routines, which means we can't * attach a linefile since filling its buffer reads in more than just the http header. * Handles 300, 301, 302, 303, 307 http redirects by setting *redirectedUrl to * the new location. */ { char buf[2000]; char *line = buf; int maxbuf = sizeof(buf); int i=0; char c = ' '; int nread = 0; char *sep = NULL; char *headerName = NULL; char *headerVal = NULL; boolean redirect = FALSE; +boolean byteRangeUsed = (strstr(url,";byterange=") != NULL); boolean mustUseProxy = FALSE; /* User must use proxy 305 error*/ char *proxyLocation = NULL; boolean mustUseProxyAuth = FALSE; /* User must use proxy authentication 407 error*/ while(TRUE) { i = 0; while (TRUE) { nread = read(sd, &c, 1); /* one char at a time, but http headers are small */ if (nread != 1) { if (nread == -1) warn("Error (%s) reading http header on %s\n", strerror(errno), url); @@ -1096,33 +1097,43 @@ return FALSE; } if (startsWith("30", code) && isdigit(code[2]) && ((code[2] >= '0' && code[2] <= '3') || code[2] == '7') && code[3] == 0) { redirect = TRUE; } else if (sameString(code, "305")) { mustUseProxy = TRUE; } else if (sameString(code, "407")) { mustUseProxyAuth = TRUE; } - else if (!(sameString(code, "200") || sameString(code, "206"))) + else if (byteRangeUsed) { - warn("%s: %s %s\n", url, code, line); + if (!sameString(code, "206")) + { + if (sameString(code, "200")) + warn("Byte-range request was ignored by server. "); + warn("Expected Partial Content 206. %s: %s %s\n", url, code, line); + return FALSE; + } + } + else if (!sameString(code, "200")) + { + warn("Expected 200 %s: %s %s\n", url, code, line); return FALSE; } line = buf; /* restore it */ } headerName = line; sep = strchr(line,':'); if (sep) { *sep = 0; headerVal = skipLeadingSpaces(++sep); } else { headerVal = NULL; }