From: Ben Gras Date: Thu, 2 Feb 2006 18:08:25 +0000 (+0000) Subject: Make urlget return errors on non-200 http codes X-Git-Tag: v3.1.2a~391 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/man.dnssec-keyfromlabel.html?a=commitdiff_plain;h=df1989aeaece61bf958ef01b1ce46b0565453c92;p=minix.git Make urlget return errors on non-200 http codes --- diff --git a/commands/urlget/urlget.c b/commands/urlget/urlget.c index 44be5e22a..37c343c15 100755 --- a/commands/urlget/urlget.c +++ b/commands/urlget/urlget.c @@ -240,8 +240,28 @@ int len; write(fd, qs, len); skip = 1; - while((s = read(fd, buffer, sizeof(buffer))) > 0) { + while((s = read(fd, buffer, sizeof(buffer)-1)) > 0) { + buffer[s] = '\0'; if(skip) { + static int firstline = 1; + if(firstline) { + static char linebuf[1000]; + int l = 0; + int c, v1, v2, e; + if(s >= sizeof(linebuf)-l) + c = sizeof(linebuf)-1-l; + else c = s; + memcpy(linebuf+l, buffer, c); + linebuf[l+c] = '\0'; + if(strchr(buffer, '\n') || strchr(buffer, '\r')) + firstline = 0; + if(sscanf(linebuf, "HTTP/%d.%d %d ", &v1, &v2, &e) == 3 + && e != 200) { + fprintf(stderr, "HTTP error %d\n", e); + return -1; + } + } + s2 = skipit(buffer, s, &skip); if(headers) write(1, buffer, s - s2);