// 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)
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);
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;
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;
}
/*}}}*/
if (Everything)
{
Persistent = false; Pipeline = false; PipelineAllowed = true;
+ RangesAllowed = true;
}
}
/*}}}*/
enum {Header, Data} State;
bool Persistent;
bool PipelineAllowed;
+ bool RangesAllowed;
std::string Location;
// This is a Persistent attribute of the server itself.
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'
configarchitecture 'amd64'
changetowebserver
-webserverconfig 'aptwebserver::support::range' 'true'
TESTFILE='aptarchive/testfile'
dd if=/dev/zero of=$TESTFILE bs=100k count=1 2>/dev/null
testrun() {
webserverconfig 'aptwebserver::support::range' 'true'
+ webserverconfig 'aptwebserver::response-header::Accept-Ranges' 'bytes'
local DOWN='./downloaded/testfile'
copysource $TESTFILE 0 $DOWN
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" '='
serverconfigs "https://localhost:${APTHTTPSPORT}"
webserverconfig 'aptwebserver::redirect::replace::/redirectme/' "https://localhost:${APTHTTPSPORT}/"
+serverconfigs "https://localhost:${APTHTTPSPORT}/redirectme"
serverconfigs "http://localhost:${APTHTTPPORT}/redirectme"
setupflataptarchive
changetowebserver
-webserverconfig 'aptwebserver::support::range' 'false'
-
prepare() {
local DATE="${2:-now}"
if [ "$DATE" = 'now' ]; then
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)