diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2008-05-10 04:50:49 +0000 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2008-05-10 04:50:49 +0000 |
| commit | 03db925988ed5defc2e925d1834059b3aed46ee9 (patch) | |
| tree | 4539275b436b281c4c8ebe1b58e2ed960b0119dd /src/HttpNullDownloadCommand.cc | |
| parent | d13b198ddda4cf7bf929766c9e479c497055bfff (diff) | |
2008-05-10 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Pool connection when a server returns 4xx, 5xx responses.
* src/HttpNullDownloadCommand.cc
* src/HttpNullDownloadCommand.h
* src/HttpResponse.cc
* src/HttpResponse.h
* src/HttpResponseCommand.cc
* src/HttpResponseCommand.h
* test/HttpResponseTest.cc
Diffstat (limited to 'src/HttpNullDownloadCommand.cc')
| -rw-r--r-- | src/HttpNullDownloadCommand.cc | 57 |
1 files changed, 44 insertions, 13 deletions
diff --git a/src/HttpNullDownloadCommand.cc b/src/HttpNullDownloadCommand.cc index a8f5098f..4ff448a9 100644 --- a/src/HttpNullDownloadCommand.cc +++ b/src/HttpNullDownloadCommand.cc @@ -44,6 +44,9 @@ #include "Logger.h" #include "HttpRequest.h" #include "Segment.h" +#include "Util.h" +#include "StringFormat.h" +#include "DlAbortEx.h" namespace aria2 { @@ -72,21 +75,30 @@ void HttpNullDownloadCommand::setTransferDecoder bool HttpNullDownloadCommand::executeInternal() { + if(_totalLength == 0 && _transferDecoder.isNull()) { + return processResponse(); + } const size_t BUFSIZE = 16*1024; unsigned char buf[BUFSIZE]; size_t bufSize = BUFSIZE; - socket->readData(buf, bufSize); - if(_transferDecoder.isNull()) { - _receivedBytes += bufSize; - } else { - // _receivedBytes is not updated if transferEncoding is set. - size_t infbufSize = 16*1024; - unsigned char infbuf[infbufSize]; - _transferDecoder->inflate(infbuf, infbufSize, buf, bufSize); - } - if(_totalLength != 0 && bufSize == 0) { - throw DlRetryEx(EX_GOT_EOF); + try { + socket->readData(buf, bufSize); + + if(_transferDecoder.isNull()) { + _receivedBytes += bufSize; + } else { + // _receivedBytes is not updated if transferEncoding is set. + size_t infbufSize = 16*1024; + unsigned char infbuf[infbufSize]; + _transferDecoder->inflate(infbuf, infbufSize, buf, bufSize); + } + if(_totalLength != 0 && bufSize == 0) { + throw DlRetryEx(EX_GOT_EOF); + } + } catch(RecoverableException& e) { + logger->debug(EX_EXCEPTION_CAUGHT, e); + return processResponse(); } if(bufSize == 0) { @@ -103,12 +115,31 @@ bool HttpNullDownloadCommand::executeInternal() socket->getPeerInfo(peerInfo); e->poolSocket(peerInfo.first, peerInfo.second, socket); } + return processResponse(); + } else { + e->commands.push_back(this); + return false; + } +} + +bool HttpNullDownloadCommand::processResponse() +{ + if(_httpResponse->isRedirect()) { _httpResponse->processRedirect(); logger->info(MSG_REDIRECT, cuid, _httpResponse->getRedirectURI().c_str()); return prepareForRetry(0); + } else if(_httpResponse->hasRetryAfter()) { + return prepareForRetry(_httpResponse->getRetryAfter()); + } else if(_httpResponse->getResponseStatus() >= "400") { + if(_httpResponse->getResponseStatus() == "401") { + throw DlAbortEx(EX_AUTH_FAILED); + }else if(_httpResponse->getResponseStatus() == "404") { + throw DlAbortEx(MSG_RESOURCE_NOT_FOUND); + } else { + throw DlAbortEx(StringFormat(EX_BAD_STATUS, Util::parseUInt(_httpResponse->getResponseStatus())).str()); + } } else { - e->commands.push_back(this); - return false; + return prepareForRetry(0); } } |
