HttpResponseCommand.cc 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  1. /* <!-- copyright */
  2. /*
  3. * aria2 - The high speed download utility
  4. *
  5. * Copyright (C) 2006 Tatsuhiro Tsujikawa
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. * In addition, as a special exception, the copyright holders give
  22. * permission to link the code of portions of this program with the
  23. * OpenSSL library under certain conditions as described in each
  24. * individual source file, and distribute linked combinations
  25. * including the two.
  26. * You must obey the GNU General Public License in all respects
  27. * for all of the code used other than OpenSSL. If you modify
  28. * file(s) with this exception, you may extend this exception to your
  29. * version of the file(s), but you are not obligated to do so. If you
  30. * do not wish to do so, delete this exception statement from your
  31. * version. If you delete this exception statement from all source
  32. * files in the program, then also delete it here.
  33. */
  34. /* copyright --> */
  35. #include "HttpResponseCommand.h"
  36. #include "DownloadEngine.h"
  37. #include "DownloadContext.h"
  38. #include "FileEntry.h"
  39. #include "RequestGroup.h"
  40. #include "RequestGroupMan.h"
  41. #include "Request.h"
  42. #include "HttpRequest.h"
  43. #include "HttpResponse.h"
  44. #include "HttpConnection.h"
  45. #include "SegmentMan.h"
  46. #include "Segment.h"
  47. #include "HttpDownloadCommand.h"
  48. #include "DiskAdaptor.h"
  49. #include "PieceStorage.h"
  50. #include "DefaultBtProgressInfoFile.h"
  51. #include "DownloadFailureException.h"
  52. #include "DlAbortEx.h"
  53. #include "util.h"
  54. #include "File.h"
  55. #include "Option.h"
  56. #include "Logger.h"
  57. #include "SocketCore.h"
  58. #include "message.h"
  59. #include "prefs.h"
  60. #include "fmt.h"
  61. #include "HttpSkipResponseCommand.h"
  62. #include "HttpHeader.h"
  63. #include "LogFactory.h"
  64. #include "CookieStorage.h"
  65. #include "AuthConfigFactory.h"
  66. #include "AuthConfig.h"
  67. #include "a2functional.h"
  68. #include "URISelector.h"
  69. #include "CheckIntegrityEntry.h"
  70. #include "StreamFilter.h"
  71. #include "SinkStreamFilter.h"
  72. #include "ChunkedDecodingStreamFilter.h"
  73. #include "uri.h"
  74. #include "SocketRecvBuffer.h"
  75. #include "MetalinkHttpEntry.h"
  76. #include "NullProgressInfoFile.h"
  77. #include "Checksum.h"
  78. #include "ChecksumCheckIntegrityEntry.h"
  79. #ifdef HAVE_ZLIB
  80. # include "GZipDecodingStreamFilter.h"
  81. #endif // HAVE_ZLIB
  82. namespace aria2 {
  83. namespace {
  84. std::unique_ptr<StreamFilter> getTransferEncodingStreamFilter
  85. (HttpResponse* httpResponse,
  86. std::unique_ptr<StreamFilter> delegate = nullptr)
  87. {
  88. if (httpResponse->isTransferEncodingSpecified()) {
  89. auto filter = httpResponse->getTransferEncodingStreamFilter();
  90. if (!filter) {
  91. throw DL_ABORT_EX(fmt(EX_TRANSFER_ENCODING_NOT_SUPPORTED,
  92. httpResponse->getTransferEncoding().c_str()));
  93. }
  94. filter->init();
  95. filter->installDelegate(std::move(delegate));
  96. return filter;
  97. }
  98. return delegate;
  99. }
  100. std::unique_ptr<StreamFilter> getContentEncodingStreamFilter
  101. (HttpResponse* httpResponse,
  102. std::unique_ptr<StreamFilter> delegate = nullptr)
  103. {
  104. if (httpResponse->isContentEncodingSpecified()) {
  105. auto filter = httpResponse->getContentEncodingStreamFilter();
  106. if (!filter) {
  107. A2_LOG_INFO(fmt("Content-Encoding %s is specified, but the current "
  108. "implementation doesn't support it. The decoding "
  109. "process is skipped and the downloaded content will be "
  110. "still encoded.",
  111. httpResponse->getContentEncoding().c_str()));
  112. }
  113. filter->init();
  114. filter->installDelegate(std::move(delegate));
  115. return filter;
  116. }
  117. return delegate;
  118. }
  119. } // namespace
  120. HttpResponseCommand::HttpResponseCommand
  121. (cuid_t cuid,
  122. const std::shared_ptr<Request>& req,
  123. const std::shared_ptr<FileEntry>& fileEntry,
  124. RequestGroup* requestGroup,
  125. const std::shared_ptr<HttpConnection>& httpConnection,
  126. DownloadEngine* e,
  127. const std::shared_ptr<SocketCore>& s)
  128. : AbstractCommand(cuid, req, fileEntry, requestGroup, e, s,
  129. httpConnection->getSocketRecvBuffer()),
  130. httpConnection_(httpConnection)
  131. {
  132. checkSocketRecvBuffer();
  133. }
  134. HttpResponseCommand::~HttpResponseCommand() {}
  135. bool HttpResponseCommand::executeInternal()
  136. {
  137. auto httpResponse = httpConnection_->receiveResponse();
  138. if (!httpResponse) {
  139. // The server has not responded to our request yet.
  140. // For socket->wantRead() == true, setReadCheckSocket(socket) is already
  141. // done in the constructor.
  142. setWriteCheckSocketIf(getSocket(), getSocket()->wantWrite());
  143. addCommandSelf();
  144. return false;
  145. }
  146. // check HTTP status code
  147. httpResponse->validateResponse();
  148. httpResponse->retrieveCookie();
  149. const auto& httpHeader = httpResponse->getHttpHeader();
  150. // Disable persistent connection if:
  151. // Connection: close is received or the remote server is not HTTP/1.1.
  152. // We don't care whether non-HTTP/1.1 server returns Connection: keep-alive.
  153. auto& req = getRequest();
  154. req->supportsPersistentConnection
  155. (httpResponse->supportsPersistentConnection());
  156. if (req->isPipeliningEnabled()) {
  157. req->setMaxPipelinedRequest
  158. (getOption()->getAsInt(PREF_MAX_HTTP_PIPELINING));
  159. }
  160. else {
  161. req->setMaxPipelinedRequest(1);
  162. }
  163. auto statusCode = httpResponse->getStatusCode();
  164. auto& ctx = getDownloadContext();
  165. auto grp = getRequestGroup();
  166. auto& fe = getFileEntry();
  167. if (statusCode == 304) {
  168. int64_t totalLength = httpResponse->getEntityLength();
  169. fe->setLength(totalLength);
  170. grp->initPieceStorage();
  171. getPieceStorage()->markAllPiecesDone();
  172. // Just set checksum verification done.
  173. ctx->setChecksumVerified(true);
  174. A2_LOG_NOTICE(fmt(MSG_DOWNLOAD_ALREADY_COMPLETED,
  175. GroupId::toHex(grp->getGID()).c_str(),
  176. grp->getFirstFilePath().c_str()));
  177. poolConnection();
  178. fe->poolRequest(req);
  179. return true;
  180. }
  181. if (!getPieceStorage()) {
  182. // Metalink/HTTP
  183. if (ctx->getAcceptMetalink()) {
  184. if (httpHeader->defined(HttpHeader::LINK)) {
  185. ctx->setAcceptMetalink(false);
  186. std::vector<MetalinkHttpEntry> entries;
  187. httpResponse->getMetalinKHttpEntries(entries, getOption());
  188. for(const auto& e : entries) {
  189. fe->addUri(e.uri);
  190. A2_LOG_DEBUG(fmt("Adding URI=%s", e.uri.c_str()));
  191. }
  192. }
  193. }
  194. if (httpHeader->defined(HttpHeader::DIGEST)) {
  195. std::vector<Checksum> checksums;
  196. httpResponse->getDigest(checksums);
  197. for(const auto &checksum : checksums) {
  198. if (ctx->getHashType().empty()) {
  199. A2_LOG_DEBUG(fmt("Setting digest: type=%s, digest=%s",
  200. checksum.getHashType().c_str(),
  201. checksum.getDigest().c_str()));
  202. ctx->setDigest(checksum.getHashType(), checksum.getDigest());
  203. break;
  204. }
  205. if (checkChecksum(ctx, checksum)) {
  206. break;
  207. }
  208. }
  209. }
  210. }
  211. if(statusCode >= 300) {
  212. if(statusCode == 404) {
  213. grp->increaseAndValidateFileNotFoundCount();
  214. }
  215. return skipResponseBody(std::move(httpResponse));
  216. }
  217. if (fe->isUniqueProtocol()) {
  218. // Redirection should be considered here. We need to parse
  219. // original URI to get hostname.
  220. const std::string& uri = getRequest()->getUri();
  221. uri_split_result us;
  222. if (uri_split(&us, uri.c_str()) == 0) {
  223. std::string host = uri::getFieldString(us, USR_HOST, uri.c_str());
  224. fe->removeURIWhoseHostnameIs(host);
  225. }
  226. }
  227. if (!getPieceStorage()) {
  228. ctx->setAcceptMetalink(false);
  229. int64_t totalLength = httpResponse->getEntityLength();
  230. fe->setLength(totalLength);
  231. if (fe->getPath().empty()) {
  232. auto suffixPath =
  233. util::createSafePath(httpResponse->determineFilename());
  234. fe->setPath(util::applyDir(getOption()->get(PREF_DIR), suffixPath));
  235. fe->setSuffixPath(suffixPath);
  236. }
  237. fe->setContentType(httpResponse->getContentType());
  238. grp->preDownloadProcessing();
  239. // update last modified time
  240. updateLastModifiedTime(httpResponse->getLastModifiedTime());
  241. // If both transfer-encoding and total length is specified, we
  242. // assume we can do segmented downloading
  243. if (totalLength == 0 || shouldInflateContentEncoding(httpResponse.get())) {
  244. // we ignore content-length when inflate is required
  245. fe->setLength(0);
  246. if (req->getMethod() == Request::METHOD_GET && (totalLength != 0 ||
  247. !httpResponse->getHttpHeader()->defined(HttpHeader::CONTENT_LENGTH))){
  248. // DownloadContext::knowsTotalLength() == true only when
  249. // server says the size of file is 0 explicitly.
  250. getDownloadContext()->markTotalLengthIsUnknown();
  251. }
  252. return handleOtherEncoding(std::move(httpResponse));
  253. }
  254. return handleDefaultEncoding(std::move(httpResponse));
  255. }
  256. if (!ctx->getHashType().empty() && httpHeader->defined(HttpHeader::DIGEST)) {
  257. std::vector<Checksum> checksums;
  258. httpResponse->getDigest(checksums);
  259. for (const auto &checksum : checksums) {
  260. if (checkChecksum(ctx, checksum)) {
  261. break;
  262. }
  263. }
  264. }
  265. // validate totalsize
  266. grp->validateTotalLength(fe->getLength(), httpResponse->getEntityLength());
  267. // update last modified time
  268. updateLastModifiedTime(httpResponse->getLastModifiedTime());
  269. if (grp->getTotalLength() == 0) {
  270. // Since total length is unknown, the file size in previously
  271. // failed download could be larger than the size this time.
  272. // Also we can't resume in this case too. So truncate the file
  273. // anyway.
  274. getPieceStorage()->getDiskAdaptor()->truncate(0);
  275. auto teFilter = getTransferEncodingStreamFilter
  276. (httpResponse.get(),
  277. getContentEncodingStreamFilter(httpResponse.get()));
  278. getDownloadEngine()->addCommand
  279. (createHttpDownloadCommand(std::move(httpResponse),
  280. std::move(teFilter)));
  281. }
  282. else {
  283. auto teFilter = getTransferEncodingStreamFilter(httpResponse.get());
  284. getDownloadEngine()->addCommand
  285. (createHttpDownloadCommand(std::move(httpResponse),
  286. std::move(teFilter)));
  287. }
  288. return true;
  289. }
  290. void HttpResponseCommand::updateLastModifiedTime(const Time& lastModified)
  291. {
  292. if (getOption()->getAsBool(PREF_REMOTE_TIME)) {
  293. getRequestGroup()->updateLastModifiedTime(lastModified);
  294. }
  295. }
  296. bool HttpResponseCommand::shouldInflateContentEncoding
  297. (HttpResponse* httpResponse)
  298. {
  299. // Basically, on the fly inflation cannot be made with segment
  300. // download, because in each segment we don't know where the date
  301. // should be written. So turn off segmented downloading.
  302. // Meanwhile, Some server returns content-encoding: gzip for .tgz
  303. // files. I think those files should not be inflated by clients,
  304. // because it is the original format of those files. Current
  305. // implementation just inflates these files nonetheless.
  306. const std::string& ce = httpResponse->getContentEncoding();
  307. return httpResponse->getHttpRequest()->acceptGZip() &&
  308. (ce == "gzip" || ce == "deflate");
  309. }
  310. bool HttpResponseCommand::handleDefaultEncoding
  311. (std::unique_ptr<HttpResponse> httpResponse)
  312. {
  313. auto progressInfoFile = std::make_shared<DefaultBtProgressInfoFile>
  314. (getDownloadContext(), std::shared_ptr<PieceStorage>{}, getOption().get());
  315. getRequestGroup()->adjustFilename(progressInfoFile);
  316. getRequestGroup()->initPieceStorage();
  317. if(getOption()->getAsBool(PREF_DRY_RUN)) {
  318. onDryRunFileFound();
  319. return true;
  320. }
  321. auto checkEntry = getRequestGroup()->createCheckIntegrityEntry();
  322. if (!checkEntry) {
  323. return true;
  324. }
  325. File file(getRequestGroup()->getFirstFilePath());
  326. // We have to make sure that command that has Request object must
  327. // have segment after PieceStorage is initialized. See
  328. // AbstractCommand::execute()
  329. auto segment = getSegmentMan()->getSegmentWithIndex(getCuid(), 0);
  330. // pipelining requires implicit range specified. But the request for
  331. // this response most likely dones't contains range header. This means
  332. // we can't continue to use this socket because server sends all entity
  333. // body instead of a segment.
  334. // Therefore, we shutdown the socket here if pipelining is enabled.
  335. if (getRequest()->getMethod() == Request::METHOD_GET &&
  336. segment && segment->getPositionToWrite() == 0 &&
  337. !getRequest()->isPipeliningEnabled()) {
  338. auto teFilter = getTransferEncodingStreamFilter(httpResponse.get());
  339. checkEntry->pushNextCommand
  340. (createHttpDownloadCommand(std::move(httpResponse),
  341. std::move(teFilter)));
  342. }
  343. else {
  344. getSegmentMan()->cancelSegment(getCuid());
  345. getFileEntry()->poolRequest(getRequest());
  346. }
  347. prepareForNextAction(std::move(checkEntry));
  348. if (getRequest()->getMethod() == Request::METHOD_HEAD) {
  349. poolConnection();
  350. getRequest()->setMethod(Request::METHOD_GET);
  351. }
  352. return true;
  353. }
  354. bool HttpResponseCommand::handleOtherEncoding
  355. (std::unique_ptr<HttpResponse> httpResponse)
  356. {
  357. // We assume that RequestGroup::getTotalLength() == 0 here
  358. if (getOption()->getAsBool(PREF_DRY_RUN)) {
  359. getRequestGroup()->initPieceStorage();
  360. onDryRunFileFound();
  361. return true;
  362. }
  363. if (getRequest()->getMethod() == Request::METHOD_HEAD) {
  364. poolConnection();
  365. getRequest()->setMethod(Request::METHOD_GET);
  366. return prepareForRetry(0);
  367. }
  368. // In this context, knowsTotalLength() is true only when the file is
  369. // really zero-length.
  370. auto streamFilter = getTransferEncodingStreamFilter
  371. (httpResponse.get(), getContentEncodingStreamFilter(httpResponse.get()));
  372. // If chunked transfer-encoding is specified, we have to read end of
  373. // chunk markers(0\r\n\r\n, for example).
  374. bool chunkedUsed = streamFilter &&
  375. streamFilter->getName() == ChunkedDecodingStreamFilter::NAME;
  376. // For zero-length file, check existing file comparing its size
  377. if (!chunkedUsed && getDownloadContext()->knowsTotalLength() &&
  378. getRequestGroup()->downloadFinishedByFileLength()) {
  379. getRequestGroup()->initPieceStorage();
  380. // TODO Known issue: if .aria2 file exists, it will not be deleted
  381. // on successful verification, because .aria2 file is not loaded.
  382. // See also FtpNegotiationCommand::onFileSizeDetermined()
  383. if(getDownloadContext()->isChecksumVerificationNeeded()) {
  384. A2_LOG_DEBUG("Zero length file exists. Verify checksum.");
  385. auto entry = make_unique<ChecksumCheckIntegrityEntry>(getRequestGroup());
  386. entry->initValidator();
  387. getPieceStorage()->getDiskAdaptor()->openExistingFile();
  388. getDownloadEngine()->getCheckIntegrityMan()->pushEntry(std::move(entry));
  389. }
  390. else {
  391. getPieceStorage()->markAllPiecesDone();
  392. getDownloadContext()->setChecksumVerified(true);
  393. A2_LOG_NOTICE(fmt(MSG_DOWNLOAD_ALREADY_COMPLETED,
  394. GroupId::toHex(getRequestGroup()->getGID()).c_str(),
  395. getRequestGroup()->getFirstFilePath().c_str()));
  396. }
  397. poolConnection();
  398. return true;
  399. }
  400. getRequestGroup()->adjustFilename(std::make_shared<NullProgressInfoFile>());
  401. getRequestGroup()->initPieceStorage();
  402. getPieceStorage()->getDiskAdaptor()->initAndOpenFile();
  403. // Local file size becomes zero when DiskAdaptor::initAndOpenFile()
  404. // is called. So zero-length file is complete if chunked encoding is
  405. // not used.
  406. if (!chunkedUsed && getDownloadContext()->knowsTotalLength()) {
  407. A2_LOG_DEBUG("File length becomes zero and it means download completed.");
  408. // TODO Known issue: if .aria2 file exists, it will not be deleted
  409. // on successful verification, because .aria2 file is not loaded.
  410. // See also FtpNegotiationCommand::onFileSizeDetermined()
  411. if (getDownloadContext()->isChecksumVerificationNeeded()) {
  412. A2_LOG_DEBUG("Verify checksum for zero-length file");
  413. auto entry = make_unique<ChecksumCheckIntegrityEntry>(getRequestGroup());
  414. entry->initValidator();
  415. getDownloadEngine()->getCheckIntegrityMan()->pushEntry(std::move(entry));
  416. } else
  417. {
  418. getRequestGroup()->getPieceStorage()->markAllPiecesDone();
  419. }
  420. poolConnection();
  421. return true;
  422. }
  423. // We have to make sure that command that has Request object must
  424. // have segment after PieceStorage is initialized. See
  425. // AbstractCommand::execute()
  426. getSegmentMan()->getSegmentWithIndex(getCuid(), 0);
  427. getDownloadEngine()->addCommand
  428. (createHttpDownloadCommand(std::move(httpResponse),
  429. std::move(streamFilter)));
  430. return true;
  431. }
  432. bool HttpResponseCommand::skipResponseBody
  433. (std::unique_ptr<HttpResponse> httpResponse)
  434. {
  435. auto filter = getTransferEncodingStreamFilter(httpResponse.get());
  436. // We don't use Content-Encoding here because this response body is just
  437. // thrown away.
  438. auto httpResponsePtr = httpResponse.get();
  439. auto command = make_unique<HttpSkipResponseCommand>
  440. (getCuid(), getRequest(), getFileEntry(), getRequestGroup(),
  441. httpConnection_, std::move(httpResponse), getDownloadEngine(),
  442. getSocket());
  443. command->installStreamFilter(std::move(filter));
  444. // If request method is HEAD or the response body is zero-length,
  445. // set command's status to real time so that avoid read check blocking
  446. if (getRequest()->getMethod() == Request::METHOD_HEAD ||
  447. (httpResponsePtr->getEntityLength() == 0 &&
  448. !httpResponsePtr->isTransferEncodingSpecified())) {
  449. command->setStatusRealtime();
  450. // If entity length == 0, then socket read/write check must be disabled.
  451. command->disableSocketCheck();
  452. getDownloadEngine()->setNoWait(true);
  453. }
  454. getDownloadEngine()->addCommand(std::move(command));
  455. return true;
  456. }
  457. namespace {
  458. bool decideFileAllocation(StreamFilter* filter)
  459. {
  460. #ifdef HAVE_ZLIB
  461. for (StreamFilter* f = filter; f; f = f->getDelegate().get()){
  462. // Since the compressed file's length are returned in the response header
  463. // and the decompressed file size is unknown at this point, disable file
  464. // allocation here.
  465. if (f->getName() == GZipDecodingStreamFilter::NAME) {
  466. return false;
  467. }
  468. }
  469. #endif // HAVE_ZLIB
  470. return true;
  471. }
  472. } // namespace
  473. std::unique_ptr<HttpDownloadCommand>
  474. HttpResponseCommand::createHttpDownloadCommand
  475. (std::unique_ptr<HttpResponse> httpResponse,
  476. std::unique_ptr<StreamFilter> filter)
  477. {
  478. auto command = make_unique<HttpDownloadCommand>
  479. (getCuid(), getRequest(), getFileEntry(), getRequestGroup(),
  480. std::move(httpResponse), httpConnection_, getDownloadEngine(),
  481. getSocket());
  482. command->setStartupIdleTime(getOption()->getAsInt(PREF_STARTUP_IDLE_TIME));
  483. command->setLowestDownloadSpeedLimit
  484. (getOption()->getAsInt(PREF_LOWEST_SPEED_LIMIT));
  485. if (getRequestGroup()->isFileAllocationEnabled() &&
  486. !decideFileAllocation(filter.get())) {
  487. getRequestGroup()->setFileAllocationEnabled(false);
  488. }
  489. command->installStreamFilter(std::move(filter));
  490. getRequestGroup()->getURISelector()->tuneDownloadCommand
  491. (getFileEntry()->getRemainingUris(), command.get());
  492. return std::move(command);
  493. }
  494. void HttpResponseCommand::poolConnection()
  495. {
  496. if (getRequest()->supportsPersistentConnection()) {
  497. getDownloadEngine()->poolSocket(getRequest(), createProxyRequest(),
  498. getSocket());
  499. }
  500. }
  501. void HttpResponseCommand::onDryRunFileFound()
  502. {
  503. getPieceStorage()->markAllPiecesDone();
  504. getDownloadContext()->setChecksumVerified(true);
  505. poolConnection();
  506. }
  507. bool HttpResponseCommand::checkChecksum
  508. (const std::shared_ptr<DownloadContext>& dctx, const Checksum& checksum)
  509. {
  510. if (dctx->getHashType() == checksum.getHashType()) {
  511. if (dctx->getDigest() != checksum.getDigest()) {
  512. throw DL_ABORT_EX("Invalid hash found in Digest header field.");
  513. }
  514. A2_LOG_INFO("Valid hash found in Digest header field.");
  515. return true;
  516. }
  517. return false;
  518. }
  519. } // namespace aria2