]> granicus.if.org Git - curl/commitdiff
http: fix the Content-Range: parser
authorDaniel Stenberg <daniel@haxx.se>
Thu, 14 Aug 2014 14:43:24 +0000 (16:43 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Fri, 15 Aug 2014 08:02:47 +0000 (10:02 +0200)
... to handle "*/[total]". Also, removed the strange hack that made
CURLOPT_FAILONERROR on a 416 response after a *RESUME_FROM return
CURLE_OK.

Reported-by: Dimitrios Siganos
Bug: http://curl.haxx.se/mail/lib-2014-06/0221.html

lib/http.c
tests/data/test194

index a695924a128a9ab77ffa5501bf7ec2a17510b390..3fdab27eee1d7bac7c6486b3962d58e069188a47 100644 (file)
@@ -920,14 +920,6 @@ static int http_should_fail(struct connectdata *conn)
   if(httpcode < 400)
     return 0;
 
-  if(data->state.resume_from &&
-     (data->set.httpreq==HTTPREQ_GET) &&
-     (httpcode == 416)) {
-    /* "Requested Range Not Satisfiable", just proceed and
-       pretend this is no error */
-    return 0;
-  }
-
   /*
   ** Any code >= 400 that's not 401 or 407 is always
   ** a terminal error
@@ -3539,23 +3531,30 @@ CURLcode Curl_http_readwrite_headers(struct SessionHandle *data,
       /* Content-Range: bytes [num]-
          Content-Range: bytes: [num]-
          Content-Range: [num]-
+         Content-Range: [asterisk]/[total]
 
          The second format was added since Sun's webserver
          JavaWebServer/1.1.1 obviously sends the header this way!
          The third added since some servers use that!
+         The forth means the requested range was unsatisfied.
       */
 
       char *ptr = k->p + 14;
 
-      /* Move forward until first digit */
-      while(*ptr && !ISDIGIT(*ptr))
+      /* Move forward until first digit or asterisk */
+      while(*ptr && !ISDIGIT(*ptr) && *ptr != '*')
         ptr++;
 
-      k->offset = curlx_strtoofft(ptr, NULL, 10);
+      /* if it truly stopped on a digit */
+      if(ISDIGIT(*ptr)) {
+        k->offset = curlx_strtoofft(ptr, NULL, 10);
 
-      if(data->state.resume_from == k->offset)
-        /* we asked for a resume and we got it */
-        k->content_range = TRUE;
+        if(data->state.resume_from == k->offset)
+          /* we asked for a resume and we got it */
+          k->content_range = TRUE;
+      }
+      else
+        data->state.resume_from = 0; /* get everything */
     }
 #if !defined(CURL_DISABLE_COOKIES)
     else if(data->cookies &&
index 1010ee906598f385b10b6d9059524cff7926282c..26f7f17bbcd9e345289e47d4bec2a3c8fb75d7f5 100644 (file)
@@ -25,6 +25,19 @@ Connection: close
 bad
 </data>
 
+<datacheck>
+HTTP/1.1 416 Requested Range Not Satisfiable swsclose\r
+Date: Fri, 24 Oct 2003 21:33:12 GMT\r
+Server: Apache/1.3.19 (Unix) (Red-Hat/Linux) mod_ssl/2.8.1 OpenSSL/0.9.6 PHP/4.3.1\r
+Last-Modified: Fri, 24 Oct 2003 18:01:23 GMT\r
+ETag: "ab57a-507-3f9968f3"\r
+Accept-Ranges: bytes\r
+Content-Length: 4\r
+Content-Range: bytes */87\r
+Content-Type: image/gif\r
+Connection: close\r
+</datacheck>
+
 </reply>
 
 # Client-side
@@ -52,6 +65,9 @@ Host: %HOSTIP:%HTTPPORT
 Accept: */*\r
 \r
 </protocol>
-
+# CURLE_HTTP_RETURNED_ERROR
+<errorcode>
+22
+</errorcode>
 </verify>
 </testcase>