Commit 09d16af4 authored by Patrick Monnerat's avatar Patrick Monnerat
Browse files

http resume: skip body if http code 416 (range error) is ignored.

This avoids appending error data to already existing good data.

Test 92 is updated to match this change.
New test 1156 checks all combinations of --range/--resume, --fail,
Content-Range header and http status code 200/416.

Fixes #1163
Reported-By: Ithubg on github
Closes #2578
parent 2e65a920
Loading
Loading
Loading
Loading
+10 −13
Original line number Diff line number Diff line
@@ -3487,22 +3487,19 @@ CURLcode Curl_http_readwrite_headers(struct Curl_easy *data,
         * depending on how authentication is working.  Other codes
         * are definitely errors, so give up here.
         */
        if(data->set.http_fail_on_error && (k->httpcode >= 400) &&
           ((k->httpcode != 401) || !conn->bits.user_passwd) &&
           ((k->httpcode != 407) || !conn->bits.proxy_user_passwd) ) {

          if(data->state.resume_from &&
             (data->set.httpreq == HTTPREQ_GET) &&
             (k->httpcode == 416)) {
        if(data->state.resume_from && data->set.httpreq == HTTPREQ_GET &&
             k->httpcode == 416) {
          /* "Requested Range Not Satisfiable", just proceed and
             pretend this is no error */
          k->ignorebody = TRUE; /* Avoid appending error msg to good data. */
        }
          else {
        else if(data->set.http_fail_on_error && (k->httpcode >= 400) &&
           ((k->httpcode != 401) || !conn->bits.user_passwd) &&
           ((k->httpcode != 407) || !conn->bits.proxy_user_passwd) ) {
          /* serious error, go home! */
          print_http_error(data);
          return CURLE_HTTP_RETURNED_ERROR;
        }
        }

        if(conn->httpversion == 10) {
          /* Default action for HTTP/1.0 must be to close, unless
+1 −1
Original line number Diff line number Diff line
@@ -127,7 +127,7 @@ test1120 test1121 test1122 test1123 test1124 test1125 test1126 test1127 \
test1128 test1129 test1130 test1131 test1132 test1133 test1134 test1135 \
test1136 test1137 test1138 test1139 test1140 test1141 test1142 test1143 \
test1144 test1145 test1146 test1147 test1148 test1149 test1150 test1151 \
test1152 test1153 test1154 test1155 \
test1152 test1153 test1154 test1155 test1156 \
\
test1160 test1161 test1162 test1163 test1164 \
test1170 test1171 \

tests/data/test1156

0 → 100644
+70 −0
Original line number Diff line number Diff line
<testcase>
<info>
<keywords>
HTTP
HTTP GET
Content-Range
Resume
Range
</keywords>
</info>

# Server-side
<reply>
<data nocheck="yes">
HTTP/1.1 200 OK
Content-Type: text/html
Content-Length: 5

body
</data>

<data1 nocheck="yes">
HTTP/1.1 200 OK
Content-Type: text/html
Content-Length: 5
Content-Range: bytes 3/7

body
</data1>

<data2 nocheck="yes">
HTTP/1.1 416 Requested Range Not Satisfiable
Content-Type: text/html
Content-Length: 5

body
</data2>

<data3 nocheck="yes">
HTTP/1.1 416 Requested Range Not Satisfiable
Content-Type: text/html
Content-Length: 5
Content-Range: bytes */2

body
</data3>
</reply>

# Client-side
<client>
<server>
http
</server>
<tool>
lib1156
</tool>
 <name>
HTTP resume/range fail range-error content-range combinations
 </name>
 <command>
http://%HOSTIP:%HTTPPORT/want/1156
</command>
</client>

# Verify data after the test has been "shot"
<verify>
<errorcode>
0
</errorcode>
</testcase>
+14 −0
Original line number Diff line number Diff line
@@ -23,6 +23,20 @@ Content-Type: image/gif

bad
</data>

# The body should be ignored.
<datacheck>
HTTP/1.1 416 Requested Range Not Satisfiable
Date: Fri, 24 Oct 2003 21:33:12 GMT
Server: Apache/1.3.19 (Unix) (Red-Hat/Linux) mod_ssl/2.8.1 OpenSSL/0.9.6 PHP/4.3.1
Last-Modified: Fri, 24 Oct 2003 18:01:23 GMT
ETag: "ab57a-507-3f9968f3"
Accept-Ranges: bytes
Content-Length: 4
Content-Range: bytes */87
Content-Type: image/gif

</datacheck>
</reply>

# Client-side
+5 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ noinst_PROGRAMS = chkhostname libauthretry libntlmconnect \
 lib571 lib572 lib573 lib574 lib575 lib576        lib578 lib579 lib582   \
 lib583 lib585 lib586 lib587 lib589 lib590 lib591 lib597 lib598 lib599   \
 lib643 lib644 lib645 lib650 lib651 lib652 lib653 lib654 lib655 \
 lib1156 \
 lib1500 lib1501 lib1502 lib1503 lib1504 lib1505 lib1506 lib1507 lib1508 \
 lib1509 lib1510 lib1511 lib1512 lib1513 lib1514 lib1515         lib1517 \
 lib1520 lib1521 \
@@ -358,6 +359,10 @@ lib1506_SOURCES = lib1506.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS)
lib1506_LDADD = $(TESTUTIL_LIBS)
lib1506_CPPFLAGS = $(AM_CPPFLAGS) -DLIB1506

lib1156_SOURCES = lib1156.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS)
lib1156_LDADD = $(TESTUTIL_LIBS)
lib1156_CPPFLAGS = $(AM_CPPFLAGS) -DLIB1156

lib1507_SOURCES = lib1507.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS)
lib1507_LDADD = $(TESTUTIL_LIBS)
lib1507_CPPFLAGS = $(AM_CPPFLAGS) -DLIB1507
Loading