]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
http: consider resume with CURLOPT_FAILONERRROR and 416 to be fine
authorDaniel Stenberg <daniel@haxx.se>
Sat, 21 Oct 2023 12:32:30 +0000 (14:32 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 30 Oct 2023 16:00:34 +0000 (17:00 +0100)
Finding a 'Content-Range:' in the response changed the handling.

Add test case 1475 to verify -C - with 416 and Content-Range: header,
which is almost exactly like test 194 which instead uses a fixed -C
offset. Adjusted test 194 to also be considered fine.

Fixes #10521
Reported-by: Smackd0wn
Fixes #12174
Reported-by: Anubhav Rai
Closes #12176

lib/http.c
tests/data/Makefile.inc
tests/data/test1475 [new file with mode: 0644]
tests/data/test194
tests/libtest/lib1156.c

index eef7802013715d68a2ad675f29f05394b6196a8d..6d6498ca725da6ced87b8324ec529b9433b9be1b 100644 (file)
@@ -3667,7 +3667,7 @@ CURLcode Curl_http_header(struct Curl_easy *data, struct connectdata *conn,
           k->content_range = TRUE;
       }
     }
-    else
+    else if(k->httpcode < 300)
       data->state.resume_from = 0; /* get everything */
   }
 #if !defined(CURL_DISABLE_COOKIES)
index a8be7f5ec7c0fcbe628c52252fa8e76987cd351a..bb651ba87c248e037eda72df4e85bc550e3d0eff 100644 (file)
@@ -185,7 +185,7 @@ test1439 test1440 test1441 test1442 test1443 test1444 test1445 test1446 \
 test1447 test1448 test1449 test1450 test1451 test1452 test1453 test1454 \
 test1455 test1456 test1457 test1458 test1459 test1460 test1461 test1462 \
 test1463 test1464 test1465 test1466 test1467 test1468 test1469 test1470 \
-test1471 test1472 test1473 test1474 \
+test1471 test1472 test1473 test1474 test1475 \
 \
 test1500 test1501 test1502 test1503 test1504 test1505 test1506 test1507 \
 test1508 test1509 test1510 test1511 test1512 test1513 test1514 test1515 \
diff --git a/tests/data/test1475 b/tests/data/test1475
new file mode 100644 (file)
index 0000000..f88ef74
--- /dev/null
@@ -0,0 +1,83 @@
+<testcase>
+# also verified by 1156 in libcurl API terms
+
+<info>
+<keywords>
+HTTP
+HTTP GET
+Resume
+</keywords>
+</info>
+
+# Server-side
+<reply>
+<data>
+HTTP/1.1 416 Invalid range\r
+Connection: close\r
+Content-Length: 0\r
+Content-Range: */100
+\r
+</data>
+
+# The file data that exists at the start of the test must be included in
+# the verification.
+<datacheck>
+012345678
+012345678
+012345678
+012345678
+012345678
+012345678
+012345678
+012345678
+012345678
+012345678
+HTTP/1.1 416 Invalid range\r
+Connection: close\r
+Content-Length: 0\r
+Content-Range: */100
+\r
+</datacheck>
+
+</reply>
+
+# Client-side
+<client>
+<server>
+http
+</server>
+<killserver>
+http
+</killserver>
+<name>
+-f and 416 with Content-Range: */size
+</name>
+<command>
+http://%HOSTIP:%HTTPPORT/%TESTNUMBER -C - -f
+</command>
+<file name="%LOGDIR/curl%TESTNUMBER.out">
+012345678
+012345678
+012345678
+012345678
+012345678
+012345678
+012345678
+012345678
+012345678
+012345678
+</file>
+</client>
+
+# Verify data after the test has been "shot"
+<verify>
+<protocol>
+GET /%TESTNUMBER HTTP/1.1\r
+Host: %HOSTIP:%HTTPPORT\r
+Range: bytes=100-\r
+User-Agent: curl/%VERSION\r
+Accept: */*\r
+\r
+</protocol>
+</verify>
+</testcase>
index 4de767e3af47b4cb187777271c556329d012e78c..074348950a946862a36cc465d1619ce55d6c78b8 100644 (file)
@@ -64,9 +64,8 @@ User-Agent: curl/%VERSION
 Accept: */*\r
 \r
 </protocol>
-# CURLE_HTTP_RETURNED_ERROR
 <errorcode>
-22
+0
 </errorcode>
 </verify>
 </testcase>
index aae2893ef377181e20f7ce413b3530a5dbadf5f4..b512ef67a9bb82fa5d15660c5d476c0b08a28afc 100644 (file)
@@ -68,7 +68,7 @@ static const struct testparams params[] = {
   { F_RESUME | F_HTTP416 |          F_CONTENTRANGE | F_IGNOREBODY, CURLE_OK },
   { F_RESUME | F_HTTP416 | F_FAIL |                  F_IGNOREBODY, CURLE_OK },
   { F_RESUME | F_HTTP416 | F_FAIL | F_CONTENTRANGE | F_IGNOREBODY,
-                                                  CURLE_HTTP_RETURNED_ERROR }
+                                                                   CURLE_OK }
 };
 
 static int      hasbody;