| 349 | } |
| 350 | |
| 351 | bool HttpResponseCommand::handleDefaultEncoding( |
| 352 | std::unique_ptr<HttpResponse> httpResponse) |
| 353 | { |
| 354 | auto progressInfoFile = std::make_shared<DefaultBtProgressInfoFile>( |
| 355 | getDownloadContext(), std::shared_ptr<PieceStorage>{}, getOption().get()); |
| 356 | getRequestGroup()->adjustFilename(progressInfoFile); |
| 357 | getRequestGroup()->initPieceStorage(); |
| 358 | |
| 359 | if (getOption()->getAsBool(PREF_DRY_RUN)) { |
| 360 | onDryRunFileFound(); |
| 361 | return true; |
| 362 | } |
| 363 | |
| 364 | auto checkEntry = getRequestGroup()->createCheckIntegrityEntry(); |
| 365 | if (!checkEntry) { |
| 366 | return true; |
| 367 | } |
| 368 | |
| 369 | File file(getRequestGroup()->getFirstFilePath()); |
| 370 | // We have to make sure that command that has Request object must |
| 371 | // have segment after PieceStorage is initialized. See |
| 372 | // AbstractCommand::execute() |
| 373 | auto segment = getSegmentMan()->getSegmentWithIndex(getCuid(), 0); |
| 374 | // pipelining requires implicit range specified. But the request for |
| 375 | // this response most likely doesn't contains range header. This means |
| 376 | // we can't continue to use this socket because server sends all entity |
| 377 | // body instead of a segment. |
| 378 | // Therefore, we shutdown the socket here if pipelining is enabled. |
| 379 | if (getRequest()->getMethod() == Request::METHOD_GET && segment && |
| 380 | segment->getPositionToWrite() == 0 && |
| 381 | !getRequest()->isPipeliningEnabled()) { |
| 382 | auto teFilter = getTransferEncodingStreamFilter(httpResponse.get()); |
| 383 | checkEntry->pushNextCommand(createHttpDownloadCommand( |
| 384 | std::move(httpResponse), std::move(teFilter))); |
| 385 | } |
| 386 | else { |
| 387 | getSegmentMan()->cancelSegment(getCuid()); |
| 388 | getFileEntry()->poolRequest(getRequest()); |
| 389 | } |
| 390 | |
| 391 | prepareForNextAction(std::move(checkEntry)); |
| 392 | |
| 393 | if (getRequest()->getMethod() == Request::METHOD_HEAD) { |
| 394 | poolConnection(); |
| 395 | getRequest()->setMethod(Request::METHOD_GET); |
| 396 | } |
| 397 | |
| 398 | return true; |
| 399 | } |
| 400 | |
| 401 | bool HttpResponseCommand::handleOtherEncoding( |
| 402 | std::unique_ptr<HttpResponse> httpResponse) |
nothing calls this directly
no test coverage detected