]> Zhao Yanbai Git Server - minix.git/commitdiff
Make urlget return errors on non-200 http codes
authorBen Gras <ben@minix3.org>
Thu, 2 Feb 2006 18:08:25 +0000 (18:08 +0000)
committerBen Gras <ben@minix3.org>
Thu, 2 Feb 2006 18:08:25 +0000 (18:08 +0000)
commands/urlget/urlget.c

index 44be5e22a7e8136878fb4c89d74542dd3c06e76c..37c343c1533ecce64013584958b93f0549edf711 100755 (executable)
@@ -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);