/* */ #include "HttpInitiateConnectionCommand.h" #include "Request.h" #include "DownloadEngine.h" #include "HttpConnection.h" #include "HttpRequest.h" #include "Segment.h" #include "HttpRequestCommand.h" #include "HttpProxyRequestCommand.h" #include "DlAbortEx.h" #include "Option.h" #include "Logger.h" #include "LogFactory.h" #include "SocketCore.h" #include "message.h" #include "prefs.h" #include "A2STR.h" #include "util.h" #include "fmt.h" #include "SocketRecvBuffer.h" #include "BackupIPv4ConnectCommand.h" #include "ConnectCommand.h" #include "HttpRequestConnectChain.h" #include "HttpProxyRequestConnectChain.h" namespace aria2 { HttpInitiateConnectionCommand::HttpInitiateConnectionCommand( cuid_t cuid, const std::shared_ptr& req, const std::shared_ptr& fileEntry, RequestGroup* requestGroup, DownloadEngine* e) : InitiateConnectionCommand(cuid, req, fileEntry, requestGroup, e) { } HttpInitiateConnectionCommand::~HttpInitiateConnectionCommand() {} std::unique_ptr HttpInitiateConnectionCommand::createNextCommand( const std::string& hostname, const std::string& addr, uint16_t port, const std::vector& resolvedAddresses, const std::shared_ptr& proxyRequest) { if (proxyRequest) { std::shared_ptr pooledSocket = getDownloadEngine()->popPooledSocket( getRequest()->getHost(), getRequest()->getPort(), proxyRequest->getHost(), proxyRequest->getPort()); std::string proxyMethod = resolveProxyMethod(getRequest()->getProtocol()); if (!pooledSocket) { A2_LOG_INFO(fmt(MSG_CONNECTING_TO_SERVER, getCuid(), addr.c_str(), port)); createSocket(); getSocket()->establishConnection(addr, port); getRequest()->setConnectedAddrInfo(hostname, addr, port); auto c = make_unique( getCuid(), getRequest(), proxyRequest, getFileEntry(), getRequestGroup(), getDownloadEngine(), getSocket()); if (proxyMethod == V_TUNNEL) { c->setControlChain(std::make_shared()); } else if (proxyMethod == V_GET) { c->setControlChain(std::make_shared()); } else { // Unreachable assert(0); } setupBackupConnection(hostname, addr, port, c.get()); return std::move(c); } else { setConnectedAddrInfo(getRequest(), hostname, pooledSocket); auto c = make_unique( getCuid(), getRequest(), getFileEntry(), getRequestGroup(), std::make_shared( getCuid(), pooledSocket, std::make_shared(pooledSocket)), getDownloadEngine(), pooledSocket); if (proxyMethod == V_GET) { c->setProxyRequest(proxyRequest); } return std::move(c); } } else { std::shared_ptr pooledSocket = getDownloadEngine()->popPooledSocket(resolvedAddresses, getRequest()->getPort()); if (!pooledSocket) { A2_LOG_INFO(fmt(MSG_CONNECTING_TO_SERVER, getCuid(), addr.c_str(), port)); createSocket(); getSocket()->establishConnection(addr, port); getRequest()->setConnectedAddrInfo(hostname, addr, port); auto c = make_unique(getCuid(), getRequest(), proxyRequest, // must be null getFileEntry(), getRequestGroup(), getDownloadEngine(), getSocket()); c->setControlChain(std::make_shared()); setupBackupConnection(hostname, addr, port, c.get()); return std::move(c); } else { setSocket(pooledSocket); setConnectedAddrInfo(getRequest(), hostname, pooledSocket); return make_unique( getCuid(), getRequest(), getFileEntry(), getRequestGroup(), std::make_shared( getCuid(), getSocket(), std::make_shared(getSocket())), getDownloadEngine(), getSocket()); } } } } // namespace aria2