mirror of https://github.com/aria2/aria2
2008-06-17 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Cancel download if http redirect is bounded more than 20 times. * src/AbstractCommand.cc * src/HttpSkipResponseCommand.cc * src/Request.cc * src/Request.h * test/RequestTest.ccpull/1/head
parent
a79e7a5fd5
commit
d4b29c84fc
|
@ -1,3 +1,12 @@
|
|||
2008-06-17 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||
|
||||
Cancel download if http redirect is bounded more than 20 times.
|
||||
* src/AbstractCommand.cc
|
||||
* src/HttpSkipResponseCommand.cc
|
||||
* src/Request.cc
|
||||
* src/Request.h
|
||||
* test/RequestTest.cc
|
||||
|
||||
2008-06-17 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||
|
||||
Fixed unhandled exception(removed keyword `new').
|
||||
|
|
|
@ -150,6 +150,7 @@ bool AbstractCommand::execute() {
|
|||
} catch(DlRetryEx& err) {
|
||||
logger->info(MSG_RESTARTING_DOWNLOAD, err, cuid, req->getUrl().c_str());
|
||||
req->addTryCount();
|
||||
req->resetRedirectCount();
|
||||
bool isAbort = e->option->getAsInt(PREF_MAX_TRIES) != 0 &&
|
||||
req->getTryCount() >= (unsigned int)e->option->getAsInt(PREF_MAX_TRIES);
|
||||
if(isAbort) {
|
||||
|
|
|
@ -129,6 +129,11 @@ bool HttpSkipResponseCommand::executeInternal()
|
|||
bool HttpSkipResponseCommand::processResponse()
|
||||
{
|
||||
if(_httpResponse->isRedirect()) {
|
||||
unsigned int rnum =
|
||||
_httpResponse->getHttpRequest()->getRequest()->getRedirectCount();
|
||||
if(rnum >= Request::MAX_REDIRECT) {
|
||||
throw DlAbortEx(StringFormat("Too many redirects: count=%u", rnum).str());
|
||||
}
|
||||
_httpResponse->processRedirect();
|
||||
logger->info(MSG_REDIRECT, cuid, _httpResponse->getRedirectURI().c_str());
|
||||
return prepareForRetry(0);
|
||||
|
|
|
@ -56,6 +56,7 @@ const std::string Request::PROTO_FTP("ftp");
|
|||
|
||||
Request::Request():
|
||||
port(0), tryCount(0),
|
||||
_redirectCount(0),
|
||||
_supportsPersistentConnection(true),
|
||||
_keepAliveHint(false),
|
||||
_pipeliningHint(false),
|
||||
|
@ -78,6 +79,7 @@ bool Request::resetUrl() {
|
|||
bool Request::redirectUrl(const std::string& url) {
|
||||
previousUrl = A2STR::NIL;
|
||||
_supportsPersistentConnection = true;
|
||||
++_redirectCount;
|
||||
return parseUrl(url);
|
||||
}
|
||||
|
||||
|
@ -198,4 +200,14 @@ void Request::urlencode(std::string& result, const std::string& src) const
|
|||
result.erase(result.size()-2);
|
||||
}
|
||||
|
||||
void Request::resetRedirectCount()
|
||||
{
|
||||
_redirectCount = 0;
|
||||
}
|
||||
|
||||
unsigned int Request::getRedirectCount() const
|
||||
{
|
||||
return _redirectCount;
|
||||
}
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -73,6 +73,8 @@ private:
|
|||
std::string _query;
|
||||
unsigned int tryCount;
|
||||
|
||||
unsigned int _redirectCount;
|
||||
|
||||
// whether or not the server supports persistent connection
|
||||
bool _supportsPersistentConnection;
|
||||
// enable keep-alive if possible.
|
||||
|
@ -111,6 +113,10 @@ public:
|
|||
unsigned int getTryCount() const { return tryCount; }
|
||||
//bool noMoreTry() const { return tryCount >= PREF_MAX_TRY; }
|
||||
|
||||
void resetRedirectCount();
|
||||
|
||||
unsigned int getRedirectCount() const;
|
||||
|
||||
const std::string& getUrl() const { return url; }
|
||||
const std::string& getCurrentUrl() const { return currentUrl; }
|
||||
const std::string& getPreviousUrl() const { return previousUrl; }
|
||||
|
@ -180,6 +186,8 @@ public:
|
|||
|
||||
static const std::string PROTO_FTP;
|
||||
|
||||
static const unsigned int MAX_REDIRECT = 20;
|
||||
|
||||
};
|
||||
|
||||
typedef SharedHandle<Request> RequestHandle;
|
||||
|
|
|
@ -291,6 +291,8 @@ void RequestTest::testRedirectUrl() {
|
|||
CPPUNIT_ASSERT_EQUAL(std::string("/"), req.getDir());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string(""), req.getFile());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string(""), req.getQuery());
|
||||
// See redirect count is incremented.
|
||||
CPPUNIT_ASSERT_EQUAL((unsigned int)1, req.getRedirectCount());
|
||||
}
|
||||
|
||||
void RequestTest::testRedirectUrl2() {
|
||||
|
|
Loading…
Reference in New Issue