always use range requests

Send "Range: bytes=0-" with the first http request to inform the server
of range support by the client.

As per RFC 7233, server MUST ignore the header (not request!) if it
doesn't support range requests or the specified unit. So, this should
have no side effects.

Fixes GH-1576.
pull/1587/head
Ali MJ Al-Nasrawy 2020-03-15 00:32:12 +03:00
parent 2924a029ab
commit 83cb6c15d3
2 changed files with 9 additions and 0 deletions

View File

@ -213,6 +213,9 @@ std::string HttpRequest::createRequest()
}
builtinHds.emplace_back("Range:", rangeHeader);
}
else if (!segment_ && getMethod() == "GET") {
builtinHds.emplace_back("Range:", "bytes=0-");
}
if (proxyRequest_) {
if (request_->isKeepAliveEnabled() || request_->isPipeliningEnabled()) {
builtinHds.emplace_back("Connection:", "Keep-Alive");

View File

@ -527,6 +527,7 @@ void HttpRequestTest::testCreateRequest_query()
"Pragma: no-cache\r\n"
"Cache-Control: no-cache\r\n"
"Connection: close\r\n"
"Range: bytes=0-\r\n"
"\r\n";
CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createRequest());
@ -624,6 +625,7 @@ void HttpRequestTest::testCreateRequest_wantDigest()
"Pragma: no-cache\r\n"
"Cache-Control: no-cache\r\n"
"Connection: close\r\n"
"Range: bytes=0-\r\n"
"Want-Digest: " +
wantDigest +
"\r\n"
@ -781,6 +783,7 @@ void HttpRequestTest::testUserAgent()
"Pragma: no-cache\r\n"
"Cache-Control: no-cache\r\n"
"Connection: close\r\n"
"Range: bytes=0-\r\n"
"\r\n";
CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createRequest());
@ -818,6 +821,7 @@ void HttpRequestTest::testAddHeader()
"Pragma: no-cache\r\n"
"Cache-Control: no-cache\r\n"
"Connection: close\r\n"
"Range: bytes=0-\r\n"
"X-ARIA2: v0.13\r\n"
"X-ARIA2-DISTRIBUTE: enabled\r\n"
"Accept: text/html\r\n"
@ -847,6 +851,7 @@ void HttpRequestTest::testAcceptMetalink()
"Pragma: no-cache\r\n"
"Cache-Control: no-cache\r\n"
"Connection: close\r\n"
"Range: bytes=0-\r\n"
"\r\n";
CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createRequest());
@ -876,6 +881,7 @@ void HttpRequestTest::testEnableAcceptEncoding()
"Pragma: no-cache\r\n"
"Cache-Control: no-cache\r\n"
"Connection: close\r\n"
"Range: bytes=0-\r\n"
"\r\n";
std::string expectedText = expectedTextHead;