summaryrefslogtreecommitdiff
path: root/methods
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2016-08-11 18:24:35 +0200
committerDavid Kalnischkies <david@kalnischkies.de>2016-08-16 18:49:37 +0200
commitd94b1d80d8326334d17f6a43061368e783b8e0aa (patch)
tree7b248c4adecf84184dc823ada6f654c7e0f46f06 /methods
parentebdb6f1810a20ac240b5b2192dc2e6532ff149d2 (diff)
don't sent Range requests if we know its not accepted
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.
Diffstat (limited to 'methods')
-rw-r--r--methods/http.cc2
-rw-r--r--methods/https.cc15
-rw-r--r--methods/server.cc10
-rw-r--r--methods/server.h1
4 files changed, 20 insertions, 8 deletions
diff --git a/methods/http.cc b/methods/http.cc
index 8d34aa6e3..11136bb9a 100644
--- a/methods/http.cc
+++ b/methods/http.cc
@@ -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)
diff --git a/methods/https.cc b/methods/https.cc
index c86f9407e..b2d05136c 100644
--- a/methods/https.cc
+++ b/methods/https.cc
@@ -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;
diff --git a/methods/server.cc b/methods/server.cc
index d0b6ef3d7..aa1ee4754 100644
--- a/methods/server.cc
+++ b/methods/server.cc
@@ -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;
}
}
/*}}}*/
diff --git a/methods/server.h b/methods/server.h
index 63acceae6..c3adba87a 100644
--- a/methods/server.h
+++ b/methods/server.h
@@ -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.