]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
resume: consider a resume from [content-length] to be OK
authorDaniel Stenberg <daniel@haxx.se>
Thu, 30 Oct 2014 13:54:59 +0000 (14:54 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Sat, 1 Nov 2014 22:09:24 +0000 (23:09 +0100)
Basically since servers often then don't respond well to this and
instead send the full contents and then libcurl would instead error out
with the assumption that the server doesn't support resume. As the data
is then already transfered, this is now considered fine.

Test case 1434 added to verify this. Test case 1042 slightly modified.

Reported-by: hugo
Bug: http://curl.haxx.se/bug/view.cgi?id=1443

lib/transfer.c
tests/data/Makefile.inc
tests/data/test1042
tests/data/test1434 [new file with mode: 0644]

index b5ba86eb402ff856b6429d488c0c945d241a2035..6d4ad43fa16e7f2e8c4bbcea10f47d7a033800b2 100644 (file)
@@ -547,6 +547,18 @@ static CURLcode readwrite_data(struct SessionHandle *data,
           if(data->state.resume_from && !k->content_range &&
              (data->set.httpreq==HTTPREQ_GET) &&
              !k->ignorebody) {
+
+            if(k->size == data->state.resume_from) {
+              /* The resume point is at the end of file, consider this fine
+                 even if it doesn't allow resume from here. */
+              infof(data, "The entire document is already downloaded");
+              connclose(conn, "already downloaded");
+              /* Abort download */
+              k->keepon &= ~KEEP_RECV;
+              *done = TRUE;
+              return CURLE_OK;
+            }
+
             /* we wanted to resume a download, although the server doesn't
              * seem to support this and we did this with a GET (if it
              * wasn't a GET we did a POST or PUT resume) */
index 6d21d670bf04569d91201baf0924ebafd1b1c514..ee9585742a26cf0dfcb9a9a6e8eeb50c9f42c0ce 100644 (file)
@@ -142,7 +142,7 @@ test1400 test1401 test1402 test1403 test1404 test1405 test1406 test1407 \
 test1408 test1409 test1410 test1411 test1412 test1413 test1414 test1415 \
 test1416 test1417 test1418 test1419 test1420 \
 \
-test1428 test1429 test1430 test1431 test1432 test1433 \
+test1428 test1429 test1430 test1431 test1432 test1433 test1434 \
 \
 test1500 test1501 test1502 test1503 test1504 test1505 test1506 test1507 \
 test1508 test1509 test1510 test1511 test1512 test1513 test1514 test1515 \
index d532120d91d45dd133a8996906860710e9ccda00..f9a2255e119989f4d35f9d0f41263c22496cd4f1 100644 (file)
@@ -56,10 +56,10 @@ Content-Type: text/plain
 http
 </server>
  <name>
-HTTP GET from end of entirely-downloaded file, no server resume
+HTTP GET beyond end of entirely-downloaded file, no server resume
  </name>
  <command>
-http://%HOSTIP:%HTTPPORT/1042 -C -
+http://%HOSTIP:%HTTPPORT/1042 -C 200
 </command>
 <file name="log/curl1042.out">
 012345678
@@ -85,7 +85,7 @@ http://%HOSTIP:%HTTPPORT/1042 -C -
 </strip>
 <protocol>
 GET /1042 HTTP/1.1\r
-Range: bytes=100-\r
+Range: bytes=200-\r
 Host: %HOSTIP:%HTTPPORT\r
 Accept: */*\r
 \r
diff --git a/tests/data/test1434 b/tests/data/test1434
new file mode 100644 (file)
index 0000000..fba104b
--- /dev/null
@@ -0,0 +1,90 @@
+<testcase>
+<info>
+<keywords>
+HTTP
+HTTP GET
+Resume
+</keywords>
+</info>
+
+# Server-side
+<reply>
+# Some servers (e.g. Apache 1.2) respond this way to an invalid byte range
+<data>
+HTTP/1.1 200 OK\r
+Connection: close\r
+Content-Length: 100\r
+Content-Type: text/plain\r
+\r
+012345678
+012345678
+012345678
+012345678
+012345678
+012345678
+012345678
+012345678
+012345678
+012345678
+</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 200 OK\r
+Connection: close\r
+Content-Length: 100\r
+Content-Type: text/plain\r
+\r
+</datacheck>
+</reply>
+
+# Client-side
+<client>
+<server>
+http
+</server>
+ <name>
+HTTP GET resume at exactly the existing file size is fine
+ </name>
+ <command>
+http://%HOSTIP:%HTTPPORT/1434 -C 100
+</command>
+<file name="log/curl1434.out">
+012345678
+012345678
+012345678
+012345678
+012345678
+012345678
+012345678
+012345678
+012345678
+012345678
+</file>
+</client>
+
+# Verify data after the test has been "shot"
+<verify>
+<strip>
+^User-Agent:.*
+</strip>
+<protocol>
+GET /1434 HTTP/1.1\r
+Range: bytes=100-\r
+Host: %HOSTIP:%HTTPPORT\r
+Accept: */*\r
+\r
+</protocol>
+</verify>
+</testcase>