| 399 | } |
| 400 | |
| 401 | bool HttpResponseCommand::handleOtherEncoding( |
| 402 | std::unique_ptr<HttpResponse> httpResponse) |
| 403 | { |
| 404 | // We assume that RequestGroup::getTotalLength() == 0 here |
| 405 | if (getOption()->getAsBool(PREF_DRY_RUN)) { |
| 406 | getRequestGroup()->initPieceStorage(); |
| 407 | onDryRunFileFound(); |
| 408 | return true; |
| 409 | } |
| 410 | |
| 411 | if (getRequest()->getMethod() == Request::METHOD_HEAD) { |
| 412 | poolConnection(); |
| 413 | getRequest()->setMethod(Request::METHOD_GET); |
| 414 | return prepareForRetry(0); |
| 415 | } |
| 416 | |
| 417 | // In this context, knowsTotalLength() is true only when the file is |
| 418 | // really zero-length. |
| 419 | |
| 420 | auto streamFilter = getTransferEncodingStreamFilter( |
| 421 | httpResponse.get(), getContentEncodingStreamFilter(httpResponse.get())); |
| 422 | // If chunked transfer-encoding is specified, we have to read end of |
| 423 | // chunk markers(0\r\n\r\n, for example). |
| 424 | bool chunkedUsed = streamFilter && streamFilter->getName() == |
| 425 | ChunkedDecodingStreamFilter::NAME; |
| 426 | |
| 427 | // For zero-length file, check existing file comparing its size |
| 428 | if (!chunkedUsed && getDownloadContext()->knowsTotalLength() && |
| 429 | getRequestGroup()->downloadFinishedByFileLength()) { |
| 430 | getRequestGroup()->initPieceStorage(); |
| 431 | |
| 432 | // TODO Known issue: if .aria2 file exists, it will not be deleted |
| 433 | // on successful verification, because .aria2 file is not loaded. |
| 434 | // See also FtpNegotiationCommand::onFileSizeDetermined() |
| 435 | if (getDownloadContext()->isChecksumVerificationNeeded()) { |
| 436 | A2_LOG_DEBUG("Zero length file exists. Verify checksum."); |
| 437 | auto entry = make_unique<ChecksumCheckIntegrityEntry>(getRequestGroup()); |
| 438 | entry->initValidator(); |
| 439 | getPieceStorage()->getDiskAdaptor()->openExistingFile(); |
| 440 | getDownloadEngine()->getCheckIntegrityMan()->pushEntry(std::move(entry)); |
| 441 | } |
| 442 | else { |
| 443 | getPieceStorage()->markAllPiecesDone(); |
| 444 | getDownloadContext()->setChecksumVerified(true); |
| 445 | A2_LOG_NOTICE(fmt(MSG_DOWNLOAD_ALREADY_COMPLETED, |
| 446 | GroupId::toHex(getRequestGroup()->getGID()).c_str(), |
| 447 | getRequestGroup()->getFirstFilePath().c_str())); |
| 448 | } |
| 449 | poolConnection(); |
| 450 | return true; |
| 451 | } |
| 452 | |
| 453 | getRequestGroup()->adjustFilename(std::make_shared<NullProgressInfoFile>()); |
| 454 | getRequestGroup()->initPieceStorage(); |
| 455 | getPieceStorage()->getDiskAdaptor()->initAndOpenFile(); |
| 456 | |
| 457 | // Local file size becomes zero when DiskAdaptor::initAndOpenFile() |
| 458 | // is called. So zero-length file is complete if chunked encoding is |
nothing calls this directly
no test coverage detected