]> git.saurik.com Git - apt.git/commitdiff
don't sent Range requests if we know its not accepted
authorDavid Kalnischkies <david@kalnischkies.de>
Thu, 11 Aug 2016 16:24:35 +0000 (18:24 +0200)
committerDavid Kalnischkies <david@kalnischkies.de>
Tue, 16 Aug 2016 16:49:37 +0000 (18:49 +0200)
If the server told us in a previous request that it isn't supporting
Ranges with bytes via an Accept-Ranges header missing bytes, we don't
try to formulate requests using Ranges.

methods/http.cc
methods/https.cc
methods/server.cc
methods/server.h
test/integration/test-apt-update-transactions
test/integration/test-bug-lp1445239-download-loop
test/integration/test-partial-file-support
test/integration/test-releasefile-verification
test/interactive-helper/aptwebserver.cc

index 8d34aa6e3b271e2f2fb7dc698a27bbd4a39bce1c..11136bb9a782a7e0e86d82d174f9d142e0ab4771 100644 (file)
@@ -906,7 +906,7 @@ void HttpMethod::SendReq(FetchItem *Itm)
 
    // Check for a partial file and send if-queries accordingly
    struct stat SBuf;
-   if (stat(Itm->DestFile.c_str(),&SBuf) >= 0 && SBuf.st_size > 0)
+   if (Server->RangesAllowed && stat(Itm->DestFile.c_str(),&SBuf) >= 0 && SBuf.st_size > 0)
       Req << "Range: bytes=" << std::to_string(SBuf.st_size) << "-\r\n"
         << "If-Range: " << TimeRFC1123(SBuf.st_mtime, false) << "\r\n";
    else if (Itm->LastModified != 0)
index c86f9407e2041880054a30f7219bae4842386567..b2d05136cd769ab1d55c7f0d6efe726cf40efcde 100644 (file)
@@ -382,8 +382,15 @@ bool HttpsMethod::Fetch(FetchItem *Itm)
         headers = curl_slist_append(headers, "Accept: text/*");
    }
 
+   // go for it - if the file exists, append on it
+   File = new FileFd(Itm->DestFile, FileFd::WriteAny);
+   if (Server == nullptr || Server->Comp(Itm->Uri) == false)
+      Server = CreateServerState(Itm->Uri);
+   else
+      Server->Reset(false);
+
    // if we have the file send an if-range query with a range header
-   if (stat(Itm->DestFile.c_str(),&SBuf) >= 0 && SBuf.st_size > 0)
+   if (Server->RangesAllowed && stat(Itm->DestFile.c_str(),&SBuf) >= 0 && SBuf.st_size > 0)
    {
       std::string Buf;
       strprintf(Buf, "Range: bytes=%lli-", (long long) SBuf.st_size);
@@ -397,12 +404,6 @@ bool HttpsMethod::Fetch(FetchItem *Itm)
       curl_easy_setopt(curl, CURLOPT_TIMEVALUE, Itm->LastModified);
    }
 
-   // go for it - if the file exists, append on it
-   File = new FileFd(Itm->DestFile, FileFd::WriteAny);
-   if (Server == nullptr || Server->Comp(Itm->Uri) == false)
-      Server = CreateServerState(Itm->Uri);
-   else
-      Server->Reset(false);
    if (Server->InitHashes(Itm->ExpectedHashes) == false)
       return false;
 
index d0b6ef3d7c5d4141f05285f9885592f67897d14e..aa1ee47543e0f7080b01f6869861ca7ca31626a6 100644 (file)
@@ -227,6 +227,15 @@ bool ServerState::HeaderLine(string Line)
       return true;
    }
 
+   if (stringcasecmp(Tag, "Accept-Ranges:") == 0)
+   {
+      std::string ranges = ',' + Val + ',';
+      ranges.erase(std::remove(ranges.begin(), ranges.end(), ' '), ranges.end());
+      if (ranges.find(",bytes,") == std::string::npos)
+        RangesAllowed = false;
+      return true;
+   }
+
    return true;
 }
                                                                        /*}}}*/
@@ -252,6 +261,7 @@ void ServerState::Reset(bool const Everything)                              /*{{{*/
    if (Everything)
    {
       Persistent = false; Pipeline = false; PipelineAllowed = true;
+      RangesAllowed = true;
    }
 }
                                                                        /*}}}*/
index 63acceae69d8527a3402cea55062804374e959f5..c3adba87a48034409e3d6cede3dded4d651d5a1f 100644 (file)
@@ -51,6 +51,7 @@ struct ServerState
    enum {Header, Data} State;
    bool Persistent;
    bool PipelineAllowed;
+   bool RangesAllowed;
    std::string Location;
 
    // This is a Persistent attribute of the server itself.
index d8154b2837afa49a828188966936385d0490c214..ab678c133a8b45d2e4b88a88401c4b579b71c29e 100755 (executable)
@@ -82,7 +82,7 @@ testsetup 'file'
 changetowebserver
 webserverconfig 'aptwebserver::support::modified-since' 'false' "$1"
 webserverconfig 'aptwebserver::support::last-modified' 'false' "$1"  # curl is clever and sees hits here also
-webserverconfig 'aptwebserver::support::range' 'false' "$1"
+webserverconfig 'aptwebserver::response-header::Accept-Ranges' 'none' "$1"
 
 testsetup 'http'
 
index a12d5252dbc877d7ccd584907459a05d5fb75356..6802840a510c20aeef3be8ecd0117a25966a2a6c 100755 (executable)
@@ -12,7 +12,6 @@ setupenvironment
 configarchitecture 'amd64'
 
 changetowebserver
-webserverconfig 'aptwebserver::support::range' 'true'
 
 TESTFILE='aptarchive/testfile'
 dd if=/dev/zero of=$TESTFILE bs=100k count=1 2>/dev/null
index 1c5d120d87aa8dc23de671ed95bf196d3360b2ce..9b5eed1e540fa50dd01b6d18579e16370b11da09 100755 (executable)
@@ -96,6 +96,7 @@ followuprequest() {
 
 testrun() {
        webserverconfig 'aptwebserver::support::range' 'true'
+       webserverconfig 'aptwebserver::response-header::Accept-Ranges' 'bytes'
        local DOWN='./downloaded/testfile'
 
        copysource $TESTFILE 0 $DOWN
@@ -125,7 +126,11 @@ testrun() {
        testdownloadfile 'old data' "${1}/testfile" "$DOWN" '='
        testwebserverlaststatuscode '200' "$DOWNLOADLOG"
 
-       webserverconfig 'aptwebserver::support::range' 'false'
+       if [ "${1%%:*}" = 'https' ] && expr match "$1" "^.*/redirectme$" >/dev/null; then
+               webserverconfig 'aptwebserver::response-header::Accept-Ranges' 'none'
+       else
+               webserverconfig 'aptwebserver::support::range' 'false'
+       fi
 
        copysource $TESTFILE 20 $DOWN
        testdownloadfile 'no server support' "${1}/testfile" "$DOWN" '='
@@ -148,4 +153,5 @@ changetohttpswebserver
 serverconfigs "https://localhost:${APTHTTPSPORT}"
 
 webserverconfig 'aptwebserver::redirect::replace::/redirectme/' "https://localhost:${APTHTTPSPORT}/"
+serverconfigs "https://localhost:${APTHTTPSPORT}/redirectme"
 serverconfigs "http://localhost:${APTHTTPPORT}/redirectme"
index 82e48ffa8d69304a978a9ac2b60e7cfc43449537..fec7b1302cd859be629b013102075a13605e99ce 100755 (executable)
@@ -12,8 +12,6 @@ buildaptarchive
 setupflataptarchive
 changetowebserver
 
-webserverconfig 'aptwebserver::support::range' 'false'
-
 prepare() {
        local DATE="${2:-now}"
        if [ "$DATE" = 'now' ]; then
index c32f286b20a6c08daa7553021eaed5ce947ceb2f..950a17bc12557e917f4486fe000832e3fb20f0f4 100644 (file)
@@ -717,6 +717,15 @@ static void * handleClient(void * voidclient)                              /*{{{*/
               condition.clear();
            if (condition.empty() == false && strncmp(condition.c_str(), "bytes=", 6) == 0)
            {
+              std::string ranges = ',' + _config->Find("aptwebserver::response-header::Accept-Ranges") + ',';
+              ranges.erase(std::remove(ranges.begin(), ranges.end(), ' '), ranges.end());
+              if (ranges.find(",bytes,") == std::string::npos)
+              {
+                 // we handle it as an error here because we are a test server - a real one should just ignore it
+                 sendError(client, 400, *m, sendContent, "Client does range requests we don't support", headers);
+                 continue;
+              }
+
               time_t cache;
               std::string ifrange;
               if (_config->FindB("aptwebserver::support::if-range", true) == true)