2006-02-17 13:35:04 +00:00
|
|
|
/* <!-- copyright */
|
|
|
|
/*
|
2006-09-21 15:31:24 +00:00
|
|
|
* aria2 - The high speed download utility
|
2006-02-17 13:35:04 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2010-01-05 16:01:46 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2006-09-21 15:31:24 +00:00
|
|
|
*
|
|
|
|
* In addition, as a special exception, the copyright holders give
|
|
|
|
* permission to link the code of portions of this program with the
|
|
|
|
* OpenSSL library under certain conditions as described in each
|
|
|
|
* individual source file, and distribute linked combinations
|
|
|
|
* including the two.
|
|
|
|
* You must obey the GNU General Public License in all respects
|
|
|
|
* for all of the code used other than OpenSSL. If you modify
|
|
|
|
* file(s) with this exception, you may extend this exception to your
|
|
|
|
* version of the file(s), but you are not obligated to do so. If you
|
|
|
|
* do not wish to do so, delete this exception statement from your
|
|
|
|
* version. If you delete this exception statement from all source
|
|
|
|
* files in the program, then also delete it here.
|
2006-02-17 13:35:04 +00:00
|
|
|
*/
|
|
|
|
/* copyright --> */
|
|
|
|
#include "HttpResponseCommand.h"
|
2007-10-11 16:58:24 +00:00
|
|
|
#include "DownloadEngine.h"
|
2009-06-28 10:37:15 +00:00
|
|
|
#include "DownloadContext.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
#include "FileEntry.h"
|
|
|
|
#include "RequestGroup.h"
|
|
|
|
#include "RequestGroupMan.h"
|
|
|
|
#include "Request.h"
|
|
|
|
#include "HttpRequest.h"
|
2007-10-11 16:58:24 +00:00
|
|
|
#include "HttpResponse.h"
|
|
|
|
#include "HttpConnection.h"
|
|
|
|
#include "SegmentMan.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
#include "Segment.h"
|
2006-02-17 13:35:04 +00:00
|
|
|
#include "HttpDownloadCommand.h"
|
2007-10-11 16:58:24 +00:00
|
|
|
#include "DiskAdaptor.h"
|
|
|
|
#include "PieceStorage.h"
|
2007-11-05 15:50:49 +00:00
|
|
|
#include "DefaultBtProgressInfoFile.h"
|
2007-11-13 11:46:58 +00:00
|
|
|
#include "DownloadFailureException.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
#include "DlAbortEx.h"
|
2009-10-22 15:35:33 +00:00
|
|
|
#include "util.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
#include "File.h"
|
|
|
|
#include "Option.h"
|
|
|
|
#include "Logger.h"
|
|
|
|
#include "Socket.h"
|
|
|
|
#include "message.h"
|
|
|
|
#include "prefs.h"
|
2008-04-27 02:22:14 +00:00
|
|
|
#include "StringFormat.h"
|
2008-05-10 04:57:33 +00:00
|
|
|
#include "HttpSkipResponseCommand.h"
|
2008-05-14 14:02:18 +00:00
|
|
|
#include "HttpHeader.h"
|
2008-06-29 14:29:36 +00:00
|
|
|
#include "LogFactory.h"
|
2008-09-01 13:46:03 +00:00
|
|
|
#include "CookieStorage.h"
|
2008-11-03 10:06:25 +00:00
|
|
|
#include "AuthConfigFactory.h"
|
2009-01-30 16:12:41 +00:00
|
|
|
#include "AuthConfig.h"
|
2009-06-06 12:33:07 +00:00
|
|
|
#include "a2functional.h"
|
2009-06-29 08:42:58 +00:00
|
|
|
#include "URISelector.h"
|
2010-06-08 14:11:36 +00:00
|
|
|
#include "ServerStatMan.h"
|
|
|
|
#include "FileAllocationEntry.h"
|
|
|
|
#include "CheckIntegrityEntry.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
|
|
|
|
namespace aria2 {
|
2006-02-17 13:35:04 +00:00
|
|
|
|
2009-04-17 13:19:17 +00:00
|
|
|
static SharedHandle<Decoder> getTransferEncodingDecoder
|
|
|
|
(const SharedHandle<HttpResponse>& httpResponse);
|
|
|
|
|
|
|
|
static SharedHandle<Decoder> getContentEncodingDecoder
|
|
|
|
(const SharedHandle<HttpResponse>& httpResponse);
|
|
|
|
|
2009-06-23 15:35:45 +00:00
|
|
|
HttpResponseCommand::HttpResponseCommand
|
2010-03-20 14:30:36 +00:00
|
|
|
(cuid_t cuid,
|
2010-02-28 12:30:11 +00:00
|
|
|
const SharedHandle<Request>& req,
|
2009-06-23 15:35:45 +00:00
|
|
|
const SharedHandle<FileEntry>& fileEntry,
|
|
|
|
RequestGroup* requestGroup,
|
|
|
|
const HttpConnectionHandle& httpConnection,
|
|
|
|
DownloadEngine* e,
|
|
|
|
const SocketHandle& s)
|
|
|
|
:AbstractCommand(cuid, req, fileEntry, requestGroup, e, s),
|
|
|
|
httpConnection(httpConnection)
|
|
|
|
{}
|
2006-02-17 13:35:04 +00:00
|
|
|
|
2007-03-15 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To handle Segment as SegmentHandle:
* src/AbstractCommand.cc (execute): Rewritten.
* src/SegmentMan.h: Segment -> SegmentHandle
Introducded HttpResponse class, HttpRequest class to improve
code
extensiveness and make it clear:
* src/HttpDownloadCommand.cc: transfer encoders are now managed
by
HttpResponse class.
* src/HttpRequest.h, src/HttpRequest.cc: New class.
* src/HttpResponse.h, src/HttpResponse.cc: New class.
* src/HttpConnection.cc: Contruction of http request were moved
to
HttpRequest class.
* src/HttpResponseCommand.h, src/HttpResponseCommand.cc:
Refactored.
* src/HttpRequestCommand.cc (executeInternal): Rewritten.
* src/HttpAuthConfig.h: New class.
* src/Range.h: New class.
To make FtpTunnel{Request, Response}Command and
HttpProxy{Request, Response}Command derived from
AbstractProxy{Request, Response}Command:
* src/FtpTunnelResponseCommand.h,
src/FtpTunnelResponseCommand.cc:
Derived from AbstractProxyRequestCommand class.
* src/FtpTunnelRequestCommand.h, src/FtpTunnelRequestCommand.cc:
Derived from AbstractProxyResponseCommand class.
* src/HttpProxyRequestCommand.h, src/HttpProxyRequestCommand.cc:
Derived from AbstractProxyRequestCommand class.
* src/HttpProxyResponseCommand.h,
src/HttpProxyResponseCommand.cc:
Derived from AbstractProxyResponseCommand class.
* src/AbstractProxyRequestCommand.h,
src/AbstractProxyRequestCommand.cc
: New class.
* src/AbstractProxyResponseCommand.h,
src/AbstractProxyResponseCommand.cc: New class.
To add netrc support:
* src/Netrc.h, src/Netrc.cc: New class.
* src/Util.h, src/Util.cc (split): New function.
* src/HttpHeader.cc (getRange): Fixed so that it inspects
"Content-Range" header instead of "Range" header.
* src/HttpHeader.h
(getStatus): Removed.
(setStatus): Removed.
* src/Segment.h
(getPositionToWrite): New function.
2007-03-15 15:07:18 +00:00
|
|
|
HttpResponseCommand::~HttpResponseCommand() {}
|
2006-02-17 13:35:04 +00:00
|
|
|
|
2007-03-15 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To handle Segment as SegmentHandle:
* src/AbstractCommand.cc (execute): Rewritten.
* src/SegmentMan.h: Segment -> SegmentHandle
Introducded HttpResponse class, HttpRequest class to improve
code
extensiveness and make it clear:
* src/HttpDownloadCommand.cc: transfer encoders are now managed
by
HttpResponse class.
* src/HttpRequest.h, src/HttpRequest.cc: New class.
* src/HttpResponse.h, src/HttpResponse.cc: New class.
* src/HttpConnection.cc: Contruction of http request were moved
to
HttpRequest class.
* src/HttpResponseCommand.h, src/HttpResponseCommand.cc:
Refactored.
* src/HttpRequestCommand.cc (executeInternal): Rewritten.
* src/HttpAuthConfig.h: New class.
* src/Range.h: New class.
To make FtpTunnel{Request, Response}Command and
HttpProxy{Request, Response}Command derived from
AbstractProxy{Request, Response}Command:
* src/FtpTunnelResponseCommand.h,
src/FtpTunnelResponseCommand.cc:
Derived from AbstractProxyRequestCommand class.
* src/FtpTunnelRequestCommand.h, src/FtpTunnelRequestCommand.cc:
Derived from AbstractProxyResponseCommand class.
* src/HttpProxyRequestCommand.h, src/HttpProxyRequestCommand.cc:
Derived from AbstractProxyRequestCommand class.
* src/HttpProxyResponseCommand.h,
src/HttpProxyResponseCommand.cc:
Derived from AbstractProxyResponseCommand class.
* src/AbstractProxyRequestCommand.h,
src/AbstractProxyRequestCommand.cc
: New class.
* src/AbstractProxyResponseCommand.h,
src/AbstractProxyResponseCommand.cc: New class.
To add netrc support:
* src/Netrc.h, src/Netrc.cc: New class.
* src/Util.h, src/Util.cc (split): New function.
* src/HttpHeader.cc (getRange): Fixed so that it inspects
"Content-Range" header instead of "Range" header.
* src/HttpHeader.h
(getStatus): Removed.
(setStatus): Removed.
* src/Segment.h
(getPositionToWrite): New function.
2007-03-15 15:07:18 +00:00
|
|
|
bool HttpResponseCommand::executeInternal()
|
|
|
|
{
|
2010-02-28 12:30:11 +00:00
|
|
|
SharedHandle<HttpRequest> httpRequest = httpConnection->getFirstHttpRequest();
|
|
|
|
SharedHandle<HttpResponse> httpResponse = httpConnection->receiveResponse();
|
2007-03-15 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To handle Segment as SegmentHandle:
* src/AbstractCommand.cc (execute): Rewritten.
* src/SegmentMan.h: Segment -> SegmentHandle
Introducded HttpResponse class, HttpRequest class to improve
code
extensiveness and make it clear:
* src/HttpDownloadCommand.cc: transfer encoders are now managed
by
HttpResponse class.
* src/HttpRequest.h, src/HttpRequest.cc: New class.
* src/HttpResponse.h, src/HttpResponse.cc: New class.
* src/HttpConnection.cc: Contruction of http request were moved
to
HttpRequest class.
* src/HttpResponseCommand.h, src/HttpResponseCommand.cc:
Refactored.
* src/HttpRequestCommand.cc (executeInternal): Rewritten.
* src/HttpAuthConfig.h: New class.
* src/Range.h: New class.
To make FtpTunnel{Request, Response}Command and
HttpProxy{Request, Response}Command derived from
AbstractProxy{Request, Response}Command:
* src/FtpTunnelResponseCommand.h,
src/FtpTunnelResponseCommand.cc:
Derived from AbstractProxyRequestCommand class.
* src/FtpTunnelRequestCommand.h, src/FtpTunnelRequestCommand.cc:
Derived from AbstractProxyResponseCommand class.
* src/HttpProxyRequestCommand.h, src/HttpProxyRequestCommand.cc:
Derived from AbstractProxyRequestCommand class.
* src/HttpProxyResponseCommand.h,
src/HttpProxyResponseCommand.cc:
Derived from AbstractProxyResponseCommand class.
* src/AbstractProxyRequestCommand.h,
src/AbstractProxyRequestCommand.cc
: New class.
* src/AbstractProxyResponseCommand.h,
src/AbstractProxyResponseCommand.cc: New class.
To add netrc support:
* src/Netrc.h, src/Netrc.cc: New class.
* src/Util.h, src/Util.cc (split): New function.
* src/HttpHeader.cc (getRange): Fixed so that it inspects
"Content-Range" header instead of "Range" header.
* src/HttpHeader.h
(getStatus): Removed.
(setStatus): Removed.
* src/Segment.h
(getPositionToWrite): New function.
2007-03-15 15:07:18 +00:00
|
|
|
if(httpResponse.isNull()) {
|
|
|
|
// The server has not responded to our request yet.
|
2008-09-27 16:06:34 +00:00
|
|
|
// For socket->wantRead() == true, setReadCheckSocket(socket) is already
|
|
|
|
// done in the constructor.
|
|
|
|
setWriteCheckSocketIf(socket, socket->wantWrite());
|
2010-06-08 14:11:36 +00:00
|
|
|
e->addCommand(this);
|
2006-02-21 12:27:17 +00:00
|
|
|
return false;
|
|
|
|
}
|
2006-02-17 13:35:04 +00:00
|
|
|
// check HTTP status number
|
2007-03-15 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To handle Segment as SegmentHandle:
* src/AbstractCommand.cc (execute): Rewritten.
* src/SegmentMan.h: Segment -> SegmentHandle
Introducded HttpResponse class, HttpRequest class to improve
code
extensiveness and make it clear:
* src/HttpDownloadCommand.cc: transfer encoders are now managed
by
HttpResponse class.
* src/HttpRequest.h, src/HttpRequest.cc: New class.
* src/HttpResponse.h, src/HttpResponse.cc: New class.
* src/HttpConnection.cc: Contruction of http request were moved
to
HttpRequest class.
* src/HttpResponseCommand.h, src/HttpResponseCommand.cc:
Refactored.
* src/HttpRequestCommand.cc (executeInternal): Rewritten.
* src/HttpAuthConfig.h: New class.
* src/Range.h: New class.
To make FtpTunnel{Request, Response}Command and
HttpProxy{Request, Response}Command derived from
AbstractProxy{Request, Response}Command:
* src/FtpTunnelResponseCommand.h,
src/FtpTunnelResponseCommand.cc:
Derived from AbstractProxyRequestCommand class.
* src/FtpTunnelRequestCommand.h, src/FtpTunnelRequestCommand.cc:
Derived from AbstractProxyResponseCommand class.
* src/HttpProxyRequestCommand.h, src/HttpProxyRequestCommand.cc:
Derived from AbstractProxyRequestCommand class.
* src/HttpProxyResponseCommand.h,
src/HttpProxyResponseCommand.cc:
Derived from AbstractProxyResponseCommand class.
* src/AbstractProxyRequestCommand.h,
src/AbstractProxyRequestCommand.cc
: New class.
* src/AbstractProxyResponseCommand.h,
src/AbstractProxyResponseCommand.cc: New class.
To add netrc support:
* src/Netrc.h, src/Netrc.cc: New class.
* src/Util.h, src/Util.cc (split): New function.
* src/HttpHeader.cc (getRange): Fixed so that it inspects
"Content-Range" header instead of "Range" header.
* src/HttpHeader.h
(getStatus): Removed.
(setStatus): Removed.
* src/Segment.h
(getPositionToWrite): New function.
2007-03-15 15:07:18 +00:00
|
|
|
httpResponse->validateResponse();
|
|
|
|
httpResponse->retrieveCookie();
|
2008-05-10 04:50:49 +00:00
|
|
|
|
2008-09-30 15:54:50 +00:00
|
|
|
SharedHandle<HttpHeader> httpHeader = httpResponse->getHttpHeader();
|
|
|
|
// Disable persistent connection if:
|
|
|
|
// Connection: close is received or the remote server is not HTTP/1.1.
|
|
|
|
// We don't care whether non-HTTP/1.1 server returns Connection: keep-alive.
|
|
|
|
req->supportsPersistentConnection
|
|
|
|
(httpResponse->supportsPersistentConnection());
|
2008-12-15 15:38:07 +00:00
|
|
|
if(req->isPipeliningEnabled()) {
|
2010-06-08 15:02:20 +00:00
|
|
|
req->setMaxPipelinedRequest
|
|
|
|
(getOption()->getAsInt(PREF_MAX_HTTP_PIPELINING));
|
2008-12-15 15:38:07 +00:00
|
|
|
}
|
2008-09-30 15:54:50 +00:00
|
|
|
|
2008-05-14 14:02:18 +00:00
|
|
|
if(httpResponse->getResponseStatus() >= HttpHeader::S300) {
|
2008-09-10 14:56:44 +00:00
|
|
|
if(httpResponse->getResponseStatus() == HttpHeader::S404) {
|
|
|
|
_requestGroup->increaseAndValidateFileNotFoundCount();
|
|
|
|
}
|
2008-05-10 04:50:49 +00:00
|
|
|
return skipResponseBody(httpResponse);
|
2006-02-17 13:35:04 +00:00
|
|
|
}
|
2009-06-29 16:43:41 +00:00
|
|
|
if(!_fileEntry->isSingleHostMultiConnectionEnabled()) {
|
2009-07-11 15:57:06 +00:00
|
|
|
// TODO redirection should be considered here. We need to parse
|
2009-06-29 16:43:41 +00:00
|
|
|
// original URI to get hostname.
|
|
|
|
_fileEntry->removeURIWhoseHostnameIs(req->getHost());
|
2007-12-12 13:53:33 +00:00
|
|
|
}
|
2007-11-10 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Don't connect server before checking file integrity at startup,
if
filesize and output file path are known.
* src/AbstractCommand.cc
* src/StreamFileAllocationEntry.cc
* src/Metalink2RequestGroup.cc
* src/RequestGroup.{h, cc}
* src/HttpResponseCommand.cc
* src/FtpNegotiationCommand.cc
Added DownloadFailureException. If it is thrown, RequestGroup
should
halt.
* src/AbstractCommand.cc
* src/DownloadFailureException.h
* src/RequestGroup.cc
Catch RecoverableException, instead of DlAbortEx.
* src/RequestGroupMan.cc
* src/FillRequestGroupCommand.cc
* src/MetaFileUtil.cc
* src/IteratableChunkChecksumValidator.cc
Now first parameter of MSG_DOWNLOAD_ABORTED is
gid(RequestGroup::
getGID())
* src/CheckIntegrityCommand.cc
* src/message.h
Print gid instead of idx.
* src/RequestGroupMan.cc
Removed exception throwers declaration.
* src/DirectDiskAdaptor.{h, cc}
* src/SocketCore.{h, cc}
* src/MultiDiskAdaptor.{h, cc}
* src/HttpConnection.{h, cc}
* src/HttpResponse.{h, cc}
* src/DiskAdaptor.{h, cc}
* src/CopyDiskAdaptor.{h, cc}
* src/MultiDiskAdaptor.{h, cc}
* src/HttpHeaderProcessor.{h, cc}
* src/AbstractSingleDiskAdaptor.{h, cc}
* src/Util.{h, cc}
* test/UtilTest.cc
* src/DefaultDiskWriter.{h, cc}
* src/FtpConnection.{h, cc}
* src/AbstractDiskWriter.{h, cc}
Removed duplicate code.
* src/StreamCheckIntegrityEntry.cc
Removed unnecessary include.
* src/DiskWriter.h
Included Exception.h
* src/option_processing.cc
Included 2 files and added doc
* src/TrackerWatcherCommand.cc
* src/SocketCore.cc (writeData): Fixed send error with GnuTLS.
2007-11-09 18:01:12 +00:00
|
|
|
if(_requestGroup->getPieceStorage().isNull()) {
|
2008-03-09 12:24:01 +00:00
|
|
|
uint64_t totalLength = httpResponse->getEntityLength();
|
2009-06-23 15:35:45 +00:00
|
|
|
_fileEntry->setLength(totalLength);
|
2009-11-28 09:05:50 +00:00
|
|
|
if(_fileEntry->getPath().empty()) {
|
2009-06-28 10:37:15 +00:00
|
|
|
_fileEntry->setPath
|
2010-01-11 14:01:20 +00:00
|
|
|
(util::applyDir
|
2010-01-11 14:32:20 +00:00
|
|
|
(getDownloadContext()->getDir(),
|
|
|
|
util::fixTaintedBasename(httpResponse->determinFilename())));
|
2009-06-28 10:37:15 +00:00
|
|
|
}
|
|
|
|
_fileEntry->setContentType(httpResponse->getContentType());
|
2007-11-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Rewritten to add content-type support.
* src/DownloadHandler.{h, cc}
* src/BtPostDownloadHandler.{h, cc}
* test/BtPostDownloadHandlerTest.cc
* src/MetalinkPostDownloadHandler.{h, cc}
* test/MetalinkPostDownloadHandlerTest.cc
* src/PostDownloadHandler.{h, cc}
* src/DownloadHandlerConstants.{h, cc}
* src/RequestGroup.cc
* src/HttpResponseCommand.cc
* src/FtpNegotiationCommand.cc
* src/SingleFileDownloadContext.{h, cc}
* src/RequestGroup.h
* src/RequestGroupCriteria.h
* src/ContentTypeRequestGroupCriteria.h
Added 'mem' option value for --follow-metalink,
--follow-torrent.
If it is give, metalink/torrent file is not written to the disk,
but
just is kept in memory. Parsing is occurred on memory.
* src/MetalinkHelper.{h, cc}
* src/MetalinkProcessor.h
* src/Xml2MetalinkProcessor.{h, cc}
* test/Xml2MetalinkProcessorTest.cc
* src/DownloadHandlerFactory.{h, cc}
* test/DownloadHandlerFactoryTest.cc
* src/PreDownloadHandler.{h, cc}
* src/OptionHandlerFactory.cc
* src/DefaultBtContext.{h, cc}
* test/DefaultBtContextTest.cc
* src/version_usage.cc
* src/Metalink2RequestGroup.{h, cc}
* src/RequestGroup.{h, cc}
* src/a2functional.h
* test/a2functionalTest.cc
* src/MemoryBufferPreDownloadHandler.{h, cc}
* src/OptionHandlerImpl.h
* src/prefs.h
* src/Util.{h, cc}
* test/UtilTest.cc
Keep DownloadResult rather than RequestGroup after downloads to
reduce
memory usage.
* src/RequestGroupMan.{h, cc}
* src/DownloadEngine.cc
* src/BtDependency.{h, cc}: Changed the type of dependee from
WeakHandle to SharedHandle because WeakHandle could be null.
* src/RequestGroup.{h, cc}
* src/DownloadEngineFactory.cc
* src/DownloadResult.h
Set totalLength after download finished
* src/UnknownLengthPieceStorage.{h, cc}
Keep torrent file specified in metalink in memory.
* src/Metalink2RequestGroup.cc
* src/BtDependency.cc
* src/TrueRequestGroupCriteria.h
Fixed the bug: seekg is used where seekp should be used.
* src/ByteArrayDiskWriter.cc
* test/ByteArraydiskWriterTest.cc
2007-11-27 12:27:10 +00:00
|
|
|
_requestGroup->preDownloadProcessing();
|
2010-06-08 14:11:36 +00:00
|
|
|
if(e->getRequestGroupMan()->isSameFileBeingDownloaded(_requestGroup)) {
|
2009-05-18 15:07:15 +00:00
|
|
|
throw DOWNLOAD_FAILURE_EXCEPTION
|
2010-01-05 16:01:46 +00:00
|
|
|
(StringFormat(EX_DUPLICATE_FILE_DOWNLOAD,
|
|
|
|
_requestGroup->getFirstFilePath().c_str()).str());
|
2007-11-13 11:46:58 +00:00
|
|
|
}
|
2008-09-07 14:38:26 +00:00
|
|
|
// update last modified time
|
|
|
|
updateLastModifiedTime(httpResponse->getLastModifiedTime());
|
|
|
|
|
2009-05-05 15:19:02 +00:00
|
|
|
// If both transfer-encoding and total length is specified, we
|
|
|
|
// assume we can do segmented downloading
|
|
|
|
if(totalLength == 0 || shouldInflateContentEncoding(httpResponse)) {
|
|
|
|
// we ignore content-length when inflate is required
|
2009-06-28 10:37:15 +00:00
|
|
|
_fileEntry->setLength(0);
|
2008-11-26 15:22:54 +00:00
|
|
|
if(req->getMethod() == Request::METHOD_GET &&
|
2010-01-05 16:01:46 +00:00
|
|
|
(totalLength != 0 ||
|
|
|
|
!httpResponse->getHttpHeader()->defined(HttpHeader::CONTENT_LENGTH))){
|
|
|
|
// DownloadContext::knowsTotalLength() == true only when
|
|
|
|
// server says the size of file is 0 explicitly.
|
|
|
|
getDownloadContext()->markTotalLengthIsUnknown();
|
2008-11-26 15:22:54 +00:00
|
|
|
}
|
2007-03-15 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To handle Segment as SegmentHandle:
* src/AbstractCommand.cc (execute): Rewritten.
* src/SegmentMan.h: Segment -> SegmentHandle
Introducded HttpResponse class, HttpRequest class to improve
code
extensiveness and make it clear:
* src/HttpDownloadCommand.cc: transfer encoders are now managed
by
HttpResponse class.
* src/HttpRequest.h, src/HttpRequest.cc: New class.
* src/HttpResponse.h, src/HttpResponse.cc: New class.
* src/HttpConnection.cc: Contruction of http request were moved
to
HttpRequest class.
* src/HttpResponseCommand.h, src/HttpResponseCommand.cc:
Refactored.
* src/HttpRequestCommand.cc (executeInternal): Rewritten.
* src/HttpAuthConfig.h: New class.
* src/Range.h: New class.
To make FtpTunnel{Request, Response}Command and
HttpProxy{Request, Response}Command derived from
AbstractProxy{Request, Response}Command:
* src/FtpTunnelResponseCommand.h,
src/FtpTunnelResponseCommand.cc:
Derived from AbstractProxyRequestCommand class.
* src/FtpTunnelRequestCommand.h, src/FtpTunnelRequestCommand.cc:
Derived from AbstractProxyResponseCommand class.
* src/HttpProxyRequestCommand.h, src/HttpProxyRequestCommand.cc:
Derived from AbstractProxyRequestCommand class.
* src/HttpProxyResponseCommand.h,
src/HttpProxyResponseCommand.cc:
Derived from AbstractProxyResponseCommand class.
* src/AbstractProxyRequestCommand.h,
src/AbstractProxyRequestCommand.cc
: New class.
* src/AbstractProxyResponseCommand.h,
src/AbstractProxyResponseCommand.cc: New class.
To add netrc support:
* src/Netrc.h, src/Netrc.cc: New class.
* src/Util.h, src/Util.cc (split): New function.
* src/HttpHeader.cc (getRange): Fixed so that it inspects
"Content-Range" header instead of "Range" header.
* src/HttpHeader.h
(getStatus): Removed.
(setStatus): Removed.
* src/Segment.h
(getPositionToWrite): New function.
2007-03-15 15:07:18 +00:00
|
|
|
return handleOtherEncoding(httpResponse);
|
|
|
|
} else {
|
|
|
|
return handleDefaultEncoding(httpResponse);
|
|
|
|
}
|
2007-11-10 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Don't connect server before checking file integrity at startup,
if
filesize and output file path are known.
* src/AbstractCommand.cc
* src/StreamFileAllocationEntry.cc
* src/Metalink2RequestGroup.cc
* src/RequestGroup.{h, cc}
* src/HttpResponseCommand.cc
* src/FtpNegotiationCommand.cc
Added DownloadFailureException. If it is thrown, RequestGroup
should
halt.
* src/AbstractCommand.cc
* src/DownloadFailureException.h
* src/RequestGroup.cc
Catch RecoverableException, instead of DlAbortEx.
* src/RequestGroupMan.cc
* src/FillRequestGroupCommand.cc
* src/MetaFileUtil.cc
* src/IteratableChunkChecksumValidator.cc
Now first parameter of MSG_DOWNLOAD_ABORTED is
gid(RequestGroup::
getGID())
* src/CheckIntegrityCommand.cc
* src/message.h
Print gid instead of idx.
* src/RequestGroupMan.cc
Removed exception throwers declaration.
* src/DirectDiskAdaptor.{h, cc}
* src/SocketCore.{h, cc}
* src/MultiDiskAdaptor.{h, cc}
* src/HttpConnection.{h, cc}
* src/HttpResponse.{h, cc}
* src/DiskAdaptor.{h, cc}
* src/CopyDiskAdaptor.{h, cc}
* src/MultiDiskAdaptor.{h, cc}
* src/HttpHeaderProcessor.{h, cc}
* src/AbstractSingleDiskAdaptor.{h, cc}
* src/Util.{h, cc}
* test/UtilTest.cc
* src/DefaultDiskWriter.{h, cc}
* src/FtpConnection.{h, cc}
* src/AbstractDiskWriter.{h, cc}
Removed duplicate code.
* src/StreamCheckIntegrityEntry.cc
Removed unnecessary include.
* src/DiskWriter.h
Included Exception.h
* src/option_processing.cc
Included 2 files and added doc
* src/TrackerWatcherCommand.cc
* src/SocketCore.cc (writeData): Fixed send error with GnuTLS.
2007-11-09 18:01:12 +00:00
|
|
|
} else {
|
|
|
|
// validate totalsize
|
2009-06-23 15:35:45 +00:00
|
|
|
_requestGroup->validateTotalLength(_fileEntry->getLength(),
|
2010-01-05 16:01:46 +00:00
|
|
|
httpResponse->getEntityLength());
|
2008-09-07 14:38:26 +00:00
|
|
|
// update last modified time
|
|
|
|
updateLastModifiedTime(httpResponse->getLastModifiedTime());
|
2009-04-17 13:19:17 +00:00
|
|
|
if(_requestGroup->getTotalLength() == 0) {
|
|
|
|
// Since total length is unknown, the file size in previously
|
|
|
|
// failed download could be larger than the size this time.
|
|
|
|
// Also we can't resume in this case too. So truncate the file
|
|
|
|
// anyway.
|
|
|
|
_requestGroup->getPieceStorage()->getDiskAdaptor()->truncate(0);
|
2010-06-08 14:11:36 +00:00
|
|
|
e->addCommand
|
2010-01-05 16:01:46 +00:00
|
|
|
(createHttpDownloadCommand(httpResponse,
|
|
|
|
getTransferEncodingDecoder(httpResponse),
|
|
|
|
getContentEncodingDecoder(httpResponse)));
|
2009-04-17 13:19:17 +00:00
|
|
|
} else {
|
2010-06-08 15:02:20 +00:00
|
|
|
e->addCommand(createHttpDownloadCommand
|
|
|
|
(httpResponse, getTransferEncodingDecoder(httpResponse)));
|
2009-04-17 13:19:17 +00:00
|
|
|
}
|
2007-11-10 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Don't connect server before checking file integrity at startup,
if
filesize and output file path are known.
* src/AbstractCommand.cc
* src/StreamFileAllocationEntry.cc
* src/Metalink2RequestGroup.cc
* src/RequestGroup.{h, cc}
* src/HttpResponseCommand.cc
* src/FtpNegotiationCommand.cc
Added DownloadFailureException. If it is thrown, RequestGroup
should
halt.
* src/AbstractCommand.cc
* src/DownloadFailureException.h
* src/RequestGroup.cc
Catch RecoverableException, instead of DlAbortEx.
* src/RequestGroupMan.cc
* src/FillRequestGroupCommand.cc
* src/MetaFileUtil.cc
* src/IteratableChunkChecksumValidator.cc
Now first parameter of MSG_DOWNLOAD_ABORTED is
gid(RequestGroup::
getGID())
* src/CheckIntegrityCommand.cc
* src/message.h
Print gid instead of idx.
* src/RequestGroupMan.cc
Removed exception throwers declaration.
* src/DirectDiskAdaptor.{h, cc}
* src/SocketCore.{h, cc}
* src/MultiDiskAdaptor.{h, cc}
* src/HttpConnection.{h, cc}
* src/HttpResponse.{h, cc}
* src/DiskAdaptor.{h, cc}
* src/CopyDiskAdaptor.{h, cc}
* src/MultiDiskAdaptor.{h, cc}
* src/HttpHeaderProcessor.{h, cc}
* src/AbstractSingleDiskAdaptor.{h, cc}
* src/Util.{h, cc}
* test/UtilTest.cc
* src/DefaultDiskWriter.{h, cc}
* src/FtpConnection.{h, cc}
* src/AbstractDiskWriter.{h, cc}
Removed duplicate code.
* src/StreamCheckIntegrityEntry.cc
Removed unnecessary include.
* src/DiskWriter.h
Included Exception.h
* src/option_processing.cc
Included 2 files and added doc
* src/TrackerWatcherCommand.cc
* src/SocketCore.cc (writeData): Fixed send error with GnuTLS.
2007-11-09 18:01:12 +00:00
|
|
|
return true;
|
2006-05-09 15:54:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-07 14:38:26 +00:00
|
|
|
void HttpResponseCommand::updateLastModifiedTime(const Time& lastModified)
|
|
|
|
{
|
2009-05-08 16:41:21 +00:00
|
|
|
if(getOption()->getAsBool(PREF_REMOTE_TIME)) {
|
2008-09-07 14:38:26 +00:00
|
|
|
_requestGroup->updateLastModifiedTime(lastModified);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-31 12:42:28 +00:00
|
|
|
bool HttpResponseCommand::shouldInflateContentEncoding
|
|
|
|
(const SharedHandle<HttpResponse>& httpResponse)
|
|
|
|
{
|
2010-04-02 14:16:10 +00:00
|
|
|
// Basically, on the fly inflation cannot be made with segment
|
|
|
|
// download, because in each segment we don't know where the date
|
|
|
|
// should be written. So turn off segmented downloading.
|
|
|
|
// Meanwhile, Some server returns content-encoding: gzip for .tgz
|
|
|
|
// files. I think those files should not be inflated by clients,
|
|
|
|
// because it is the original format of those files. Current
|
|
|
|
// implementation just inflates these files nonetheless.
|
|
|
|
const std::string& ce = httpResponse->getContentEncoding();
|
|
|
|
return httpResponse->getHttpRequest()->acceptGZip() &&
|
|
|
|
(ce == "gzip" || ce == "deflate");
|
2008-07-31 12:42:28 +00:00
|
|
|
}
|
|
|
|
|
2010-02-28 12:30:11 +00:00
|
|
|
bool HttpResponseCommand::handleDefaultEncoding
|
|
|
|
(const SharedHandle<HttpResponse>& httpResponse)
|
2007-03-15 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To handle Segment as SegmentHandle:
* src/AbstractCommand.cc (execute): Rewritten.
* src/SegmentMan.h: Segment -> SegmentHandle
Introducded HttpResponse class, HttpRequest class to improve
code
extensiveness and make it clear:
* src/HttpDownloadCommand.cc: transfer encoders are now managed
by
HttpResponse class.
* src/HttpRequest.h, src/HttpRequest.cc: New class.
* src/HttpResponse.h, src/HttpResponse.cc: New class.
* src/HttpConnection.cc: Contruction of http request were moved
to
HttpRequest class.
* src/HttpResponseCommand.h, src/HttpResponseCommand.cc:
Refactored.
* src/HttpRequestCommand.cc (executeInternal): Rewritten.
* src/HttpAuthConfig.h: New class.
* src/Range.h: New class.
To make FtpTunnel{Request, Response}Command and
HttpProxy{Request, Response}Command derived from
AbstractProxy{Request, Response}Command:
* src/FtpTunnelResponseCommand.h,
src/FtpTunnelResponseCommand.cc:
Derived from AbstractProxyRequestCommand class.
* src/FtpTunnelRequestCommand.h, src/FtpTunnelRequestCommand.cc:
Derived from AbstractProxyResponseCommand class.
* src/HttpProxyRequestCommand.h, src/HttpProxyRequestCommand.cc:
Derived from AbstractProxyRequestCommand class.
* src/HttpProxyResponseCommand.h,
src/HttpProxyResponseCommand.cc:
Derived from AbstractProxyResponseCommand class.
* src/AbstractProxyRequestCommand.h,
src/AbstractProxyRequestCommand.cc
: New class.
* src/AbstractProxyResponseCommand.h,
src/AbstractProxyResponseCommand.cc: New class.
To add netrc support:
* src/Netrc.h, src/Netrc.cc: New class.
* src/Util.h, src/Util.cc (split): New function.
* src/HttpHeader.cc (getRange): Fixed so that it inspects
"Content-Range" header instead of "Range" header.
* src/HttpHeader.h
(getStatus): Removed.
(setStatus): Removed.
* src/Segment.h
(getPositionToWrite): New function.
2007-03-15 15:07:18 +00:00
|
|
|
{
|
2010-02-28 12:30:11 +00:00
|
|
|
SharedHandle<HttpRequest> httpRequest = httpResponse->getHttpRequest();
|
2009-05-07 03:49:27 +00:00
|
|
|
_requestGroup->adjustFilename
|
|
|
|
(SharedHandle<BtProgressInfoFile>(new DefaultBtProgressInfoFile
|
2010-01-05 16:01:46 +00:00
|
|
|
(_requestGroup->getDownloadContext(),
|
|
|
|
SharedHandle<PieceStorage>(),
|
|
|
|
getOption().get())));
|
2007-11-10 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Don't connect server before checking file integrity at startup,
if
filesize and output file path are known.
* src/AbstractCommand.cc
* src/StreamFileAllocationEntry.cc
* src/Metalink2RequestGroup.cc
* src/RequestGroup.{h, cc}
* src/HttpResponseCommand.cc
* src/FtpNegotiationCommand.cc
Added DownloadFailureException. If it is thrown, RequestGroup
should
halt.
* src/AbstractCommand.cc
* src/DownloadFailureException.h
* src/RequestGroup.cc
Catch RecoverableException, instead of DlAbortEx.
* src/RequestGroupMan.cc
* src/FillRequestGroupCommand.cc
* src/MetaFileUtil.cc
* src/IteratableChunkChecksumValidator.cc
Now first parameter of MSG_DOWNLOAD_ABORTED is
gid(RequestGroup::
getGID())
* src/CheckIntegrityCommand.cc
* src/message.h
Print gid instead of idx.
* src/RequestGroupMan.cc
Removed exception throwers declaration.
* src/DirectDiskAdaptor.{h, cc}
* src/SocketCore.{h, cc}
* src/MultiDiskAdaptor.{h, cc}
* src/HttpConnection.{h, cc}
* src/HttpResponse.{h, cc}
* src/DiskAdaptor.{h, cc}
* src/CopyDiskAdaptor.{h, cc}
* src/MultiDiskAdaptor.{h, cc}
* src/HttpHeaderProcessor.{h, cc}
* src/AbstractSingleDiskAdaptor.{h, cc}
* src/Util.{h, cc}
* test/UtilTest.cc
* src/DefaultDiskWriter.{h, cc}
* src/FtpConnection.{h, cc}
* src/AbstractDiskWriter.{h, cc}
Removed duplicate code.
* src/StreamCheckIntegrityEntry.cc
Removed unnecessary include.
* src/DiskWriter.h
Included Exception.h
* src/option_processing.cc
Included 2 files and added doc
* src/TrackerWatcherCommand.cc
* src/SocketCore.cc (writeData): Fixed send error with GnuTLS.
2007-11-09 18:01:12 +00:00
|
|
|
_requestGroup->initPieceStorage();
|
2007-10-11 16:58:24 +00:00
|
|
|
|
2009-05-08 16:41:21 +00:00
|
|
|
if(getOption()->getAsBool(PREF_DRY_RUN)) {
|
2009-03-08 10:20:42 +00:00
|
|
|
onDryRunFileFound();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-06-08 15:02:20 +00:00
|
|
|
BtProgressInfoFileHandle infoFile
|
|
|
|
(new DefaultBtProgressInfoFile(_requestGroup->getDownloadContext(),
|
|
|
|
_requestGroup->getPieceStorage(),
|
|
|
|
getOption().get()));
|
2007-11-10 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Don't connect server before checking file integrity at startup,
if
filesize and output file path are known.
* src/AbstractCommand.cc
* src/StreamFileAllocationEntry.cc
* src/Metalink2RequestGroup.cc
* src/RequestGroup.{h, cc}
* src/HttpResponseCommand.cc
* src/FtpNegotiationCommand.cc
Added DownloadFailureException. If it is thrown, RequestGroup
should
halt.
* src/AbstractCommand.cc
* src/DownloadFailureException.h
* src/RequestGroup.cc
Catch RecoverableException, instead of DlAbortEx.
* src/RequestGroupMan.cc
* src/FillRequestGroupCommand.cc
* src/MetaFileUtil.cc
* src/IteratableChunkChecksumValidator.cc
Now first parameter of MSG_DOWNLOAD_ABORTED is
gid(RequestGroup::
getGID())
* src/CheckIntegrityCommand.cc
* src/message.h
Print gid instead of idx.
* src/RequestGroupMan.cc
Removed exception throwers declaration.
* src/DirectDiskAdaptor.{h, cc}
* src/SocketCore.{h, cc}
* src/MultiDiskAdaptor.{h, cc}
* src/HttpConnection.{h, cc}
* src/HttpResponse.{h, cc}
* src/DiskAdaptor.{h, cc}
* src/CopyDiskAdaptor.{h, cc}
* src/MultiDiskAdaptor.{h, cc}
* src/HttpHeaderProcessor.{h, cc}
* src/AbstractSingleDiskAdaptor.{h, cc}
* src/Util.{h, cc}
* test/UtilTest.cc
* src/DefaultDiskWriter.{h, cc}
* src/FtpConnection.{h, cc}
* src/AbstractDiskWriter.{h, cc}
Removed duplicate code.
* src/StreamCheckIntegrityEntry.cc
Removed unnecessary include.
* src/DiskWriter.h
Included Exception.h
* src/option_processing.cc
Included 2 files and added doc
* src/TrackerWatcherCommand.cc
* src/SocketCore.cc (writeData): Fixed send error with GnuTLS.
2007-11-09 18:01:12 +00:00
|
|
|
if(!infoFile->exists() && _requestGroup->downloadFinishedByFileLength()) {
|
2009-05-07 03:49:27 +00:00
|
|
|
_requestGroup->getPieceStorage()->markAllPiecesDone();
|
|
|
|
|
2010-06-08 15:02:20 +00:00
|
|
|
getLogger()->notice(MSG_DOWNLOAD_ALREADY_COMPLETED,
|
|
|
|
util::itos(_requestGroup->getGID()).c_str(),
|
|
|
|
_requestGroup->getFirstFilePath().c_str());
|
2009-05-07 03:49:27 +00:00
|
|
|
|
2007-11-10 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Don't connect server before checking file integrity at startup,
if
filesize and output file path are known.
* src/AbstractCommand.cc
* src/StreamFileAllocationEntry.cc
* src/Metalink2RequestGroup.cc
* src/RequestGroup.{h, cc}
* src/HttpResponseCommand.cc
* src/FtpNegotiationCommand.cc
Added DownloadFailureException. If it is thrown, RequestGroup
should
halt.
* src/AbstractCommand.cc
* src/DownloadFailureException.h
* src/RequestGroup.cc
Catch RecoverableException, instead of DlAbortEx.
* src/RequestGroupMan.cc
* src/FillRequestGroupCommand.cc
* src/MetaFileUtil.cc
* src/IteratableChunkChecksumValidator.cc
Now first parameter of MSG_DOWNLOAD_ABORTED is
gid(RequestGroup::
getGID())
* src/CheckIntegrityCommand.cc
* src/message.h
Print gid instead of idx.
* src/RequestGroupMan.cc
Removed exception throwers declaration.
* src/DirectDiskAdaptor.{h, cc}
* src/SocketCore.{h, cc}
* src/MultiDiskAdaptor.{h, cc}
* src/HttpConnection.{h, cc}
* src/HttpResponse.{h, cc}
* src/DiskAdaptor.{h, cc}
* src/CopyDiskAdaptor.{h, cc}
* src/MultiDiskAdaptor.{h, cc}
* src/HttpHeaderProcessor.{h, cc}
* src/AbstractSingleDiskAdaptor.{h, cc}
* src/Util.{h, cc}
* test/UtilTest.cc
* src/DefaultDiskWriter.{h, cc}
* src/FtpConnection.{h, cc}
* src/AbstractDiskWriter.{h, cc}
Removed duplicate code.
* src/StreamCheckIntegrityEntry.cc
Removed unnecessary include.
* src/DiskWriter.h
Included Exception.h
* src/option_processing.cc
Included 2 files and added doc
* src/TrackerWatcherCommand.cc
* src/SocketCore.cc (writeData): Fixed send error with GnuTLS.
2007-11-09 18:01:12 +00:00
|
|
|
return true;
|
2006-02-17 13:35:04 +00:00
|
|
|
}
|
2010-06-01 12:40:57 +00:00
|
|
|
_requestGroup->loadAndOpenFile(infoFile);
|
|
|
|
File file(_requestGroup->getFirstFilePath());
|
|
|
|
// We have to make sure that command that has Request object must
|
|
|
|
// have segment after PieceStorage is initialized. See
|
|
|
|
// AbstractCommand::execute()
|
|
|
|
SharedHandle<Segment> segment =
|
2010-06-08 15:02:20 +00:00
|
|
|
_requestGroup->getSegmentMan()->getSegment(getCuid(), 0);
|
2010-06-01 12:40:57 +00:00
|
|
|
// pipelining requires implicit range specified. But the request for
|
|
|
|
// this response most likely dones't contains range header. This means
|
|
|
|
// we can't continue to use this socket because server sends all entity
|
|
|
|
// body instead of a segment.
|
|
|
|
// Therefore, we shutdown the socket here if pipelining is enabled.
|
2007-05-31 15:56:20 +00:00
|
|
|
DownloadCommand* command = 0;
|
2010-06-01 12:40:57 +00:00
|
|
|
if(req->getMethod() == Request::METHOD_GET &&
|
|
|
|
!segment.isNull() && segment->getPositionToWrite() == 0 &&
|
|
|
|
!req->isPipeliningEnabled()) {
|
|
|
|
command = createHttpDownloadCommand
|
|
|
|
(httpResponse, getTransferEncodingDecoder(httpResponse));
|
|
|
|
} else {
|
2010-06-08 15:02:20 +00:00
|
|
|
_requestGroup->getSegmentMan()->cancelSegment(getCuid());
|
2010-06-01 12:40:57 +00:00
|
|
|
_fileEntry->poolRequest(req);
|
|
|
|
}
|
|
|
|
// After command is passed to prepareForNextAction(), it is managed
|
|
|
|
// by CheckIntegrityEntry.
|
|
|
|
prepareForNextAction(command);
|
|
|
|
command = 0;
|
|
|
|
if(req->getMethod() == Request::METHOD_HEAD) {
|
|
|
|
poolConnection();
|
|
|
|
req->setMethod(Request::METHOD_GET);
|
2007-05-31 15:56:20 +00:00
|
|
|
}
|
2007-05-20 13:51:52 +00:00
|
|
|
return true;
|
2006-02-17 13:35:04 +00:00
|
|
|
}
|
|
|
|
|
2008-07-01 11:38:25 +00:00
|
|
|
static SharedHandle<Decoder> getTransferEncodingDecoder
|
2008-05-06 15:20:59 +00:00
|
|
|
(const SharedHandle<HttpResponse>& httpResponse)
|
2007-03-15 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To handle Segment as SegmentHandle:
* src/AbstractCommand.cc (execute): Rewritten.
* src/SegmentMan.h: Segment -> SegmentHandle
Introducded HttpResponse class, HttpRequest class to improve
code
extensiveness and make it clear:
* src/HttpDownloadCommand.cc: transfer encoders are now managed
by
HttpResponse class.
* src/HttpRequest.h, src/HttpRequest.cc: New class.
* src/HttpResponse.h, src/HttpResponse.cc: New class.
* src/HttpConnection.cc: Contruction of http request were moved
to
HttpRequest class.
* src/HttpResponseCommand.h, src/HttpResponseCommand.cc:
Refactored.
* src/HttpRequestCommand.cc (executeInternal): Rewritten.
* src/HttpAuthConfig.h: New class.
* src/Range.h: New class.
To make FtpTunnel{Request, Response}Command and
HttpProxy{Request, Response}Command derived from
AbstractProxy{Request, Response}Command:
* src/FtpTunnelResponseCommand.h,
src/FtpTunnelResponseCommand.cc:
Derived from AbstractProxyRequestCommand class.
* src/FtpTunnelRequestCommand.h, src/FtpTunnelRequestCommand.cc:
Derived from AbstractProxyResponseCommand class.
* src/HttpProxyRequestCommand.h, src/HttpProxyRequestCommand.cc:
Derived from AbstractProxyRequestCommand class.
* src/HttpProxyResponseCommand.h,
src/HttpProxyResponseCommand.cc:
Derived from AbstractProxyResponseCommand class.
* src/AbstractProxyRequestCommand.h,
src/AbstractProxyRequestCommand.cc
: New class.
* src/AbstractProxyResponseCommand.h,
src/AbstractProxyResponseCommand.cc: New class.
To add netrc support:
* src/Netrc.h, src/Netrc.cc: New class.
* src/Util.h, src/Util.cc (split): New function.
* src/HttpHeader.cc (getRange): Fixed so that it inspects
"Content-Range" header instead of "Range" header.
* src/HttpHeader.h
(getStatus): Removed.
(setStatus): Removed.
* src/Segment.h
(getPositionToWrite): New function.
2007-03-15 15:07:18 +00:00
|
|
|
{
|
2008-07-01 11:38:25 +00:00
|
|
|
SharedHandle<Decoder> decoder;
|
2007-03-15 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To handle Segment as SegmentHandle:
* src/AbstractCommand.cc (execute): Rewritten.
* src/SegmentMan.h: Segment -> SegmentHandle
Introducded HttpResponse class, HttpRequest class to improve
code
extensiveness and make it clear:
* src/HttpDownloadCommand.cc: transfer encoders are now managed
by
HttpResponse class.
* src/HttpRequest.h, src/HttpRequest.cc: New class.
* src/HttpResponse.h, src/HttpResponse.cc: New class.
* src/HttpConnection.cc: Contruction of http request were moved
to
HttpRequest class.
* src/HttpResponseCommand.h, src/HttpResponseCommand.cc:
Refactored.
* src/HttpRequestCommand.cc (executeInternal): Rewritten.
* src/HttpAuthConfig.h: New class.
* src/Range.h: New class.
To make FtpTunnel{Request, Response}Command and
HttpProxy{Request, Response}Command derived from
AbstractProxy{Request, Response}Command:
* src/FtpTunnelResponseCommand.h,
src/FtpTunnelResponseCommand.cc:
Derived from AbstractProxyRequestCommand class.
* src/FtpTunnelRequestCommand.h, src/FtpTunnelRequestCommand.cc:
Derived from AbstractProxyResponseCommand class.
* src/HttpProxyRequestCommand.h, src/HttpProxyRequestCommand.cc:
Derived from AbstractProxyRequestCommand class.
* src/HttpProxyResponseCommand.h,
src/HttpProxyResponseCommand.cc:
Derived from AbstractProxyResponseCommand class.
* src/AbstractProxyRequestCommand.h,
src/AbstractProxyRequestCommand.cc
: New class.
* src/AbstractProxyResponseCommand.h,
src/AbstractProxyResponseCommand.cc: New class.
To add netrc support:
* src/Netrc.h, src/Netrc.cc: New class.
* src/Util.h, src/Util.cc (split): New function.
* src/HttpHeader.cc (getRange): Fixed so that it inspects
"Content-Range" header instead of "Range" header.
* src/HttpHeader.h
(getStatus): Removed.
(setStatus): Removed.
* src/Segment.h
(getPositionToWrite): New function.
2007-03-15 15:07:18 +00:00
|
|
|
if(httpResponse->isTransferEncodingSpecified()) {
|
2008-07-01 11:38:25 +00:00
|
|
|
decoder = httpResponse->getTransferEncodingDecoder();
|
|
|
|
if(decoder.isNull()) {
|
2009-05-18 15:07:15 +00:00
|
|
|
throw DL_ABORT_EX
|
2010-01-05 16:01:46 +00:00
|
|
|
(StringFormat(EX_TRANSFER_ENCODING_NOT_SUPPORTED,
|
|
|
|
httpResponse->getTransferEncoding().c_str()).str());
|
2007-03-15 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To handle Segment as SegmentHandle:
* src/AbstractCommand.cc (execute): Rewritten.
* src/SegmentMan.h: Segment -> SegmentHandle
Introducded HttpResponse class, HttpRequest class to improve
code
extensiveness and make it clear:
* src/HttpDownloadCommand.cc: transfer encoders are now managed
by
HttpResponse class.
* src/HttpRequest.h, src/HttpRequest.cc: New class.
* src/HttpResponse.h, src/HttpResponse.cc: New class.
* src/HttpConnection.cc: Contruction of http request were moved
to
HttpRequest class.
* src/HttpResponseCommand.h, src/HttpResponseCommand.cc:
Refactored.
* src/HttpRequestCommand.cc (executeInternal): Rewritten.
* src/HttpAuthConfig.h: New class.
* src/Range.h: New class.
To make FtpTunnel{Request, Response}Command and
HttpProxy{Request, Response}Command derived from
AbstractProxy{Request, Response}Command:
* src/FtpTunnelResponseCommand.h,
src/FtpTunnelResponseCommand.cc:
Derived from AbstractProxyRequestCommand class.
* src/FtpTunnelRequestCommand.h, src/FtpTunnelRequestCommand.cc:
Derived from AbstractProxyResponseCommand class.
* src/HttpProxyRequestCommand.h, src/HttpProxyRequestCommand.cc:
Derived from AbstractProxyRequestCommand class.
* src/HttpProxyResponseCommand.h,
src/HttpProxyResponseCommand.cc:
Derived from AbstractProxyResponseCommand class.
* src/AbstractProxyRequestCommand.h,
src/AbstractProxyRequestCommand.cc
: New class.
* src/AbstractProxyResponseCommand.h,
src/AbstractProxyResponseCommand.cc: New class.
To add netrc support:
* src/Netrc.h, src/Netrc.cc: New class.
* src/Util.h, src/Util.cc (split): New function.
* src/HttpHeader.cc (getRange): Fixed so that it inspects
"Content-Range" header instead of "Range" header.
* src/HttpHeader.h
(getStatus): Removed.
(setStatus): Removed.
* src/Segment.h
(getPositionToWrite): New function.
2007-03-15 15:07:18 +00:00
|
|
|
}
|
2008-07-01 11:38:25 +00:00
|
|
|
decoder->init();
|
2007-03-15 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To handle Segment as SegmentHandle:
* src/AbstractCommand.cc (execute): Rewritten.
* src/SegmentMan.h: Segment -> SegmentHandle
Introducded HttpResponse class, HttpRequest class to improve
code
extensiveness and make it clear:
* src/HttpDownloadCommand.cc: transfer encoders are now managed
by
HttpResponse class.
* src/HttpRequest.h, src/HttpRequest.cc: New class.
* src/HttpResponse.h, src/HttpResponse.cc: New class.
* src/HttpConnection.cc: Contruction of http request were moved
to
HttpRequest class.
* src/HttpResponseCommand.h, src/HttpResponseCommand.cc:
Refactored.
* src/HttpRequestCommand.cc (executeInternal): Rewritten.
* src/HttpAuthConfig.h: New class.
* src/Range.h: New class.
To make FtpTunnel{Request, Response}Command and
HttpProxy{Request, Response}Command derived from
AbstractProxy{Request, Response}Command:
* src/FtpTunnelResponseCommand.h,
src/FtpTunnelResponseCommand.cc:
Derived from AbstractProxyRequestCommand class.
* src/FtpTunnelRequestCommand.h, src/FtpTunnelRequestCommand.cc:
Derived from AbstractProxyResponseCommand class.
* src/HttpProxyRequestCommand.h, src/HttpProxyRequestCommand.cc:
Derived from AbstractProxyRequestCommand class.
* src/HttpProxyResponseCommand.h,
src/HttpProxyResponseCommand.cc:
Derived from AbstractProxyResponseCommand class.
* src/AbstractProxyRequestCommand.h,
src/AbstractProxyRequestCommand.cc
: New class.
* src/AbstractProxyResponseCommand.h,
src/AbstractProxyResponseCommand.cc: New class.
To add netrc support:
* src/Netrc.h, src/Netrc.cc: New class.
* src/Util.h, src/Util.cc (split): New function.
* src/HttpHeader.cc (getRange): Fixed so that it inspects
"Content-Range" header instead of "Range" header.
* src/HttpHeader.h
(getStatus): Removed.
(setStatus): Removed.
* src/Segment.h
(getPositionToWrite): New function.
2007-03-15 15:07:18 +00:00
|
|
|
}
|
2008-07-01 11:38:25 +00:00
|
|
|
return decoder;
|
2008-05-06 15:20:59 +00:00
|
|
|
}
|
|
|
|
|
2008-06-29 14:29:36 +00:00
|
|
|
static SharedHandle<Decoder> getContentEncodingDecoder
|
|
|
|
(const SharedHandle<HttpResponse>& httpResponse)
|
|
|
|
{
|
|
|
|
SharedHandle<Decoder> decoder;
|
|
|
|
if(httpResponse->isContentEncodingSpecified()) {
|
|
|
|
decoder = httpResponse->getContentEncodingDecoder();
|
|
|
|
if(decoder.isNull()) {
|
|
|
|
LogFactory::getInstance()->info
|
2010-01-05 16:01:46 +00:00
|
|
|
("Content-Encoding %s is specified, but the current implementation"
|
|
|
|
"doesn't support it. The decoding process is skipped and the"
|
|
|
|
"downloaded content will be still encoded.",
|
|
|
|
httpResponse->getContentEncoding().c_str());
|
2008-06-29 14:29:36 +00:00
|
|
|
} else {
|
|
|
|
decoder->init();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return decoder;
|
|
|
|
}
|
|
|
|
|
2010-02-28 12:30:11 +00:00
|
|
|
bool HttpResponseCommand::handleOtherEncoding
|
|
|
|
(const SharedHandle<HttpResponse>& httpResponse) {
|
2008-11-26 15:22:54 +00:00
|
|
|
// We assume that RequestGroup::getTotalLength() == 0 here
|
2010-02-28 12:30:11 +00:00
|
|
|
SharedHandle<HttpRequest> httpRequest = httpResponse->getHttpRequest();
|
2009-03-08 10:20:42 +00:00
|
|
|
|
2009-05-08 16:41:21 +00:00
|
|
|
if(getOption()->getAsBool(PREF_DRY_RUN)) {
|
2009-03-08 10:20:42 +00:00
|
|
|
_requestGroup->initPieceStorage();
|
|
|
|
onDryRunFileFound();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-11-23 15:00:44 +00:00
|
|
|
if(req->getMethod() == Request::METHOD_HEAD) {
|
2008-11-26 15:22:54 +00:00
|
|
|
poolConnection();
|
2008-11-23 15:00:44 +00:00
|
|
|
req->setMethod(Request::METHOD_GET);
|
|
|
|
return prepareForRetry(0);
|
2008-09-01 15:06:29 +00:00
|
|
|
}
|
2008-11-26 15:22:54 +00:00
|
|
|
|
|
|
|
// For zero-length file, check existing file comparing its size
|
2009-05-07 03:49:27 +00:00
|
|
|
if(_requestGroup->downloadFinishedByFileLength()) {
|
|
|
|
_requestGroup->initPieceStorage();
|
|
|
|
_requestGroup->getPieceStorage()->markAllPiecesDone();
|
|
|
|
|
2010-06-08 15:02:20 +00:00
|
|
|
getLogger()->notice(MSG_DOWNLOAD_ALREADY_COMPLETED,
|
|
|
|
util::itos(_requestGroup->getGID()).c_str(),
|
|
|
|
_requestGroup->getFirstFilePath().c_str());
|
2009-05-07 03:49:27 +00:00
|
|
|
|
2008-11-26 15:22:54 +00:00
|
|
|
poolConnection();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-09-01 15:06:29 +00:00
|
|
|
_requestGroup->shouldCancelDownloadForSafety();
|
2009-05-07 03:49:27 +00:00
|
|
|
_requestGroup->initPieceStorage();
|
|
|
|
|
2008-09-01 15:06:29 +00:00
|
|
|
_requestGroup->getPieceStorage()->getDiskAdaptor()->initAndOpenFile();
|
2008-11-26 15:22:54 +00:00
|
|
|
|
2009-04-17 13:19:17 +00:00
|
|
|
// In this context, knowsTotalLength() is true only when the file is
|
|
|
|
// really zero-length.
|
2008-11-26 15:22:54 +00:00
|
|
|
if(_requestGroup->getDownloadContext()->knowsTotalLength()) {
|
|
|
|
poolConnection();
|
|
|
|
return true;
|
|
|
|
}
|
2010-03-28 07:23:33 +00:00
|
|
|
// We have to make sure that command that has Request object must
|
|
|
|
// have segment after PieceStorage is initialized. See
|
|
|
|
// AbstractCommand::execute()
|
2010-06-08 15:02:20 +00:00
|
|
|
_requestGroup->getSegmentMan()->getSegment(getCuid(), 0);
|
2010-03-28 07:23:33 +00:00
|
|
|
|
2010-06-08 14:11:36 +00:00
|
|
|
e->addCommand
|
2008-09-01 15:06:29 +00:00
|
|
|
(createHttpDownloadCommand(httpResponse,
|
2010-01-05 16:01:46 +00:00
|
|
|
getTransferEncodingDecoder(httpResponse),
|
|
|
|
getContentEncodingDecoder(httpResponse)));
|
2008-09-01 15:06:29 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-05-10 04:50:49 +00:00
|
|
|
bool HttpResponseCommand::skipResponseBody
|
2008-05-06 15:20:59 +00:00
|
|
|
(const SharedHandle<HttpResponse>& httpResponse)
|
|
|
|
{
|
2008-07-01 11:38:25 +00:00
|
|
|
SharedHandle<Decoder> decoder = getTransferEncodingDecoder(httpResponse);
|
2008-06-29 14:29:36 +00:00
|
|
|
// We don't use Content-Encoding here because this response body is just
|
|
|
|
// thrown away.
|
|
|
|
|
2008-05-10 04:57:33 +00:00
|
|
|
HttpSkipResponseCommand* command = new HttpSkipResponseCommand
|
2010-06-08 15:02:20 +00:00
|
|
|
(getCuid(), req, _fileEntry, _requestGroup, httpConnection, httpResponse,
|
|
|
|
e, socket);
|
2008-07-01 11:38:25 +00:00
|
|
|
command->setTransferEncodingDecoder(decoder);
|
2008-05-10 04:50:49 +00:00
|
|
|
|
2008-11-23 15:00:44 +00:00
|
|
|
// If request method is HEAD or the response body is zero-length,
|
|
|
|
// set command's status to real time so that avoid read check blocking
|
|
|
|
if(req->getMethod() == Request::METHOD_HEAD ||
|
|
|
|
(httpResponse->getEntityLength() == 0 &&
|
|
|
|
!httpResponse->isTransferEncodingSpecified())) {
|
2008-05-10 04:50:49 +00:00
|
|
|
command->setStatusRealtime();
|
2008-10-22 12:20:48 +00:00
|
|
|
// If entity length == 0, then socket read/write check must be disabled.
|
|
|
|
command->disableSocketCheck();
|
2008-05-10 04:50:49 +00:00
|
|
|
e->setNoWait(true);
|
|
|
|
}
|
|
|
|
|
2010-06-08 14:11:36 +00:00
|
|
|
e->addCommand(command);
|
2008-05-06 15:20:59 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-07-01 11:38:25 +00:00
|
|
|
HttpDownloadCommand* HttpResponseCommand::createHttpDownloadCommand
|
2010-02-28 12:30:11 +00:00
|
|
|
(const SharedHandle<HttpResponse>& httpResponse,
|
2008-09-01 15:06:29 +00:00
|
|
|
const SharedHandle<Decoder>& transferEncodingDecoder,
|
|
|
|
const SharedHandle<Decoder>& contentEncodingDecoder)
|
2008-05-06 15:20:59 +00:00
|
|
|
{
|
2008-06-29 14:29:36 +00:00
|
|
|
|
2007-05-20 13:51:52 +00:00
|
|
|
HttpDownloadCommand* command =
|
2010-06-08 15:02:20 +00:00
|
|
|
new HttpDownloadCommand(getCuid(), req, _fileEntry, _requestGroup,
|
2010-01-05 16:01:46 +00:00
|
|
|
httpResponse, httpConnection, e, socket);
|
2009-05-08 16:41:21 +00:00
|
|
|
command->setStartupIdleTime(getOption()->getAsInt(PREF_STARTUP_IDLE_TIME));
|
2008-07-01 11:38:25 +00:00
|
|
|
command->setLowestDownloadSpeedLimit
|
2009-05-08 16:41:21 +00:00
|
|
|
(getOption()->getAsInt(PREF_LOWEST_SPEED_LIMIT));
|
2008-07-01 11:38:25 +00:00
|
|
|
command->setTransferEncodingDecoder(transferEncodingDecoder);
|
2007-03-15 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To handle Segment as SegmentHandle:
* src/AbstractCommand.cc (execute): Rewritten.
* src/SegmentMan.h: Segment -> SegmentHandle
Introducded HttpResponse class, HttpRequest class to improve
code
extensiveness and make it clear:
* src/HttpDownloadCommand.cc: transfer encoders are now managed
by
HttpResponse class.
* src/HttpRequest.h, src/HttpRequest.cc: New class.
* src/HttpResponse.h, src/HttpResponse.cc: New class.
* src/HttpConnection.cc: Contruction of http request were moved
to
HttpRequest class.
* src/HttpResponseCommand.h, src/HttpResponseCommand.cc:
Refactored.
* src/HttpRequestCommand.cc (executeInternal): Rewritten.
* src/HttpAuthConfig.h: New class.
* src/Range.h: New class.
To make FtpTunnel{Request, Response}Command and
HttpProxy{Request, Response}Command derived from
AbstractProxy{Request, Response}Command:
* src/FtpTunnelResponseCommand.h,
src/FtpTunnelResponseCommand.cc:
Derived from AbstractProxyRequestCommand class.
* src/FtpTunnelRequestCommand.h, src/FtpTunnelRequestCommand.cc:
Derived from AbstractProxyResponseCommand class.
* src/HttpProxyRequestCommand.h, src/HttpProxyRequestCommand.cc:
Derived from AbstractProxyRequestCommand class.
* src/HttpProxyResponseCommand.h,
src/HttpProxyResponseCommand.cc:
Derived from AbstractProxyResponseCommand class.
* src/AbstractProxyRequestCommand.h,
src/AbstractProxyRequestCommand.cc
: New class.
* src/AbstractProxyResponseCommand.h,
src/AbstractProxyResponseCommand.cc: New class.
To add netrc support:
* src/Netrc.h, src/Netrc.cc: New class.
* src/Util.h, src/Util.cc (split): New function.
* src/HttpHeader.cc (getRange): Fixed so that it inspects
"Content-Range" header instead of "Range" header.
* src/HttpHeader.h
(getStatus): Removed.
(setStatus): Removed.
* src/Segment.h
(getPositionToWrite): New function.
2007-03-15 15:07:18 +00:00
|
|
|
|
2008-09-01 15:06:29 +00:00
|
|
|
if(!contentEncodingDecoder.isNull()) {
|
2008-06-29 14:29:36 +00:00
|
|
|
command->setContentEncodingDecoder(contentEncodingDecoder);
|
|
|
|
// Since the compressed file's length are returned in the response header
|
|
|
|
// and the decompressed file size is unknown at this point, disable file
|
|
|
|
// allocation here.
|
|
|
|
_requestGroup->setFileAllocationEnabled(false);
|
|
|
|
}
|
|
|
|
|
2009-06-29 08:42:58 +00:00
|
|
|
_requestGroup->getURISelector()->tuneDownloadCommand
|
|
|
|
(_fileEntry->getRemainingUris(), command);
|
2009-01-06 13:13:42 +00:00
|
|
|
|
2007-05-31 15:56:20 +00:00
|
|
|
return command;
|
2006-02-17 13:35:04 +00:00
|
|
|
}
|
2008-02-08 15:53:45 +00:00
|
|
|
|
2008-11-26 15:22:54 +00:00
|
|
|
void HttpResponseCommand::poolConnection()
|
|
|
|
{
|
|
|
|
if(req->supportsPersistentConnection()) {
|
2010-05-21 13:54:50 +00:00
|
|
|
e->poolSocket(req, createProxyRequest(), socket);
|
2008-11-26 15:22:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-08 10:20:42 +00:00
|
|
|
void HttpResponseCommand::onDryRunFileFound()
|
|
|
|
{
|
|
|
|
_requestGroup->getPieceStorage()->markAllPiecesDone();
|
|
|
|
poolConnection();
|
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
} // namespace aria2
|