2008-11-04 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

Deprecated --http-proxy-user and --http-proxy-passwd options.
	Added --https-proxy, --ftp-proxy and --all-proxy options.
	Above 3 options and --http-proxy option can handle proxy in URL
	format like: http://user:passwd@host:port.
	If a proxy requires user/password, they must be specified in a
	URL.
	Deprecated --ftp-via-http-proxy option. Use --http-proxy-method
	option instead.
	* src/AbstractCommand.cc
	* src/AbstractCommand.h
	* src/AbstractProxyRequestCommand.cc
	* src/AbstractProxyRequestCommand.h
	* src/AuthConfigFactory.cc
	* src/AuthConfigFactory.h
	* src/FtpFinishDownloadCommand.cc
	* src/FtpInitiateConnectionCommand.cc
	* src/FtpInitiateConnectionCommand.h
	* src/FtpNegotiationCommand.cc
	* src/FtpTunnelRequestCommand.cc
	* src/FtpTunnelRequestCommand.h
	* src/HttpDownloadCommand.cc
	* src/HttpInitiateConnectionCommand.cc
	* src/HttpInitiateConnectionCommand.h
	* src/HttpProxyRequestCommand.cc
	* src/HttpProxyRequestCommand.h
	* src/HttpRequest.cc
	* src/HttpRequest.h
	* src/HttpRequestCommand.cc
	* src/HttpRequestCommand.h
	* src/HttpSkipResponseCommand.cc
	* src/InitiateConnectionCommand.cc
	* src/InitiateConnectionCommand.h
	* src/OptionHandlerFactory.cc
	* src/OptionHandlerImpl.h
	* src/Request.cc
	* src/option_processing.cc
	* src/prefs.cc
	* src/prefs.h
	* src/usage_text.h
	* test/AuthConfigFactoryTest.cc
	* test/HttpRequestTest.cc
	* test/OptionHandlerTest.cc
pull/1/head
Tatsuhiro Tsujikawa 2008-11-04 14:08:26 +00:00
parent 223621b5bc
commit c7fb678e6e
35 changed files with 432 additions and 372 deletions

View File

@ -1,3 +1,47 @@
2008-11-04 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Deprecated --http-proxy-user and --http-proxy-passwd options.
Added --https-proxy, --ftp-proxy and --all-proxy options.
Above 3 options and --http-proxy option can handle proxy in URL format
like: http://user:passwd@host:port.
If a proxy requires user/password, they must be specified in a URL.
Deprecated --ftp-via-http-proxy option. Use --http-proxy-method option
instead.
* src/AbstractCommand.cc
* src/AbstractCommand.h
* src/AbstractProxyRequestCommand.cc
* src/AbstractProxyRequestCommand.h
* src/AuthConfigFactory.cc
* src/AuthConfigFactory.h
* src/FtpFinishDownloadCommand.cc
* src/FtpInitiateConnectionCommand.cc
* src/FtpInitiateConnectionCommand.h
* src/FtpNegotiationCommand.cc
* src/FtpTunnelRequestCommand.cc
* src/FtpTunnelRequestCommand.h
* src/HttpDownloadCommand.cc
* src/HttpInitiateConnectionCommand.cc
* src/HttpInitiateConnectionCommand.h
* src/HttpProxyRequestCommand.cc
* src/HttpProxyRequestCommand.h
* src/HttpRequest.cc
* src/HttpRequest.h
* src/HttpRequestCommand.cc
* src/HttpRequestCommand.h
* src/HttpSkipResponseCommand.cc
* src/InitiateConnectionCommand.cc
* src/InitiateConnectionCommand.h
* src/OptionHandlerFactory.cc
* src/OptionHandlerImpl.h
* src/Request.cc
* src/option_processing.cc
* src/prefs.cc
* src/prefs.h
* src/usage_text.h
* test/AuthConfigFactoryTest.cc
* test/HttpRequestTest.cc
* test/OptionHandlerTest.cc
2008-11-03 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> 2008-11-03 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Execute choking algorithm when unchoked and interested peer is Execute choking algorithm when unchoked and interested peer is

View File

@ -57,6 +57,7 @@
#include "StringFormat.h" #include "StringFormat.h"
#include "ServerStat.h" #include "ServerStat.h"
#include "RequestGroupMan.h" #include "RequestGroupMan.h"
#include "A2STR.h"
namespace aria2 { namespace aria2 {
@ -291,17 +292,76 @@ void AbstractCommand::setWriteCheckSocketIf
} }
} }
static bool isProxyGETRequest(const std::string& protocol, const Option* option) static const std::string& getProxyStringFor(const std::string& proxyPref,
const Option* option)
{
if(option->defined(proxyPref)) {
return option->get(proxyPref);
} else {
return option->get(PREF_ALL_PROXY);
}
}
static bool isProxyUsed(const std::string& proxyPref,
const Option* option)
{
std::string proxy = getProxyStringFor(proxyPref, option);
if(proxy.empty()) {
return false;
} else {
return Request().setUrl(proxy);
}
}
static bool isProxyRequest(const std::string& protocol, const Option* option)
{ {
return return
// For HTTP/HTTPS (protocol == Request::PROTO_HTTP && isProxyUsed(PREF_HTTP_PROXY, option)) ||
((protocol == Request::PROTO_HTTP || protocol == Request::PROTO_HTTPS) && (protocol == Request::PROTO_HTTPS && isProxyUsed(PREF_HTTPS_PROXY,option))||
(option->getAsBool(PREF_HTTP_PROXY_ENABLED) && (protocol == Request::PROTO_FTP && isProxyUsed(PREF_FTP_PROXY, option));
option->get(PREF_HTTP_PROXY_METHOD) == V_GET)) || }
// For FTP
(protocol == Request::PROTO_FTP && static bool isProxyGETRequest(const std::string& protocol, const Option* option)
(option->getAsBool(PREF_HTTP_PROXY_ENABLED) && {
option->get(PREF_FTP_VIA_HTTP_PROXY) == V_GET)); if(option->get(PREF_HTTP_PROXY_METHOD) != V_GET) {
return false;
}
return isProxyRequest(protocol, option);
}
bool AbstractCommand::isProxyDefined() const
{
return isProxyRequest(req->getProtocol(), e->option);
}
static const std::string& getProxyString(const SharedHandle<Request>& req,
const Option* option)
{
if(req->getProtocol() == Request::PROTO_HTTP) {
return getProxyStringFor(PREF_HTTP_PROXY, option);
} else if(req->getProtocol() == Request::PROTO_HTTPS) {
return getProxyStringFor(PREF_HTTPS_PROXY, option);
} else if(req->getProtocol() == Request::PROTO_FTP) {
return getProxyStringFor(PREF_FTP_PROXY, option);
} else {
return A2STR::NIL;
}
}
SharedHandle<Request> AbstractCommand::createProxyRequest() const
{
SharedHandle<Request> proxyRequest;
std::string proxy = getProxyString(req, e->option);
if(!proxy.empty()) {
proxyRequest.reset(new Request());
if(proxyRequest->setUrl(proxy)) {
logger->debug("CUID#%d - Using proxy", cuid);
} else {
logger->debug("CUID#%d - Failed to parse proxy string", cuid);
proxyRequest.reset();
}
}
return proxyRequest;
} }
#ifdef ENABLE_ASYNC_DNS #ifdef ENABLE_ASYNC_DNS
@ -325,7 +385,7 @@ bool AbstractCommand::asyncResolveHostname()
case AsyncNameResolver::STATUS_SUCCESS: case AsyncNameResolver::STATUS_SUCCESS:
return true; return true;
case AsyncNameResolver::STATUS_ERROR: case AsyncNameResolver::STATUS_ERROR:
if(!isProxyGETRequest(req->getProtocol(), e->option)) { if(!isProxyRequest(req->getProtocol(), e->option)) {
e->_requestGroupMan->getOrCreateServerStat e->_requestGroupMan->getOrCreateServerStat
(req->getHost(), req->getProtocol())->setError(); (req->getHost(), req->getProtocol())->setError();
} }

View File

@ -100,6 +100,18 @@ protected:
void prepareForNextAction(Command* nextCommand = 0); void prepareForNextAction(Command* nextCommand = 0);
void checkIfConnectionEstablished(const SharedHandle<SocketCore>& socket); void checkIfConnectionEstablished(const SharedHandle<SocketCore>& socket);
/*
* Returns true if proxy for the procol indicated by Request::getProtocol()
* is defined. Otherwise, returns false.
*/
bool isProxyDefined() const;
/*
* Creates Request object for proxy URI and returns it.
* If no valid proxy is defined, then returns SharedHandle<Request>().
*/
SharedHandle<Request> createProxyRequest() const;
private: private:
bool checkSocketIsReadable; bool checkSocketIsReadable;
bool checkSocketIsWritable; bool checkSocketIsWritable;

View File

@ -47,13 +47,17 @@
namespace aria2 { namespace aria2 {
AbstractProxyRequestCommand::AbstractProxyRequestCommand(int cuid, AbstractProxyRequestCommand::AbstractProxyRequestCommand
const RequestHandle& req, (int cuid,
RequestGroup* requestGroup, const RequestHandle& req,
DownloadEngine* e, RequestGroup* requestGroup,
const SocketHandle& s) DownloadEngine* e,
:AbstractCommand(cuid, req, requestGroup, e, s), const SharedHandle<Request>& proxyRequest,
httpConnection(new HttpConnection(cuid, s, e->option)) const SocketHandle& s)
:
AbstractCommand(cuid, req, requestGroup, e, s),
_proxyRequest(proxyRequest),
httpConnection(new HttpConnection(cuid, s, e->option))
{ {
setTimeout(e->option->getAsInt(PREF_CONNECT_TIMEOUT)); setTimeout(e->option->getAsInt(PREF_CONNECT_TIMEOUT));
disableReadCheckSocket(); disableReadCheckSocket();
@ -69,8 +73,7 @@ bool AbstractProxyRequestCommand::executeInternal() {
httpRequest->setUserAgent(e->option->get(PREF_USER_AGENT)); httpRequest->setUserAgent(e->option->get(PREF_USER_AGENT));
httpRequest->setRequest(req); httpRequest->setRequest(req);
httpRequest->setAuthConfigFactory(e->getAuthConfigFactory()); httpRequest->setAuthConfigFactory(e->getAuthConfigFactory());
httpRequest->setProxyRequest(_proxyRequest);
httpRequest->configure(e->option);
httpConnection->sendProxyRequest(httpRequest); httpConnection->sendProxyRequest(httpRequest);
} else { } else {

View File

@ -44,6 +44,8 @@ class SocketCore;
class AbstractProxyRequestCommand : public AbstractCommand { class AbstractProxyRequestCommand : public AbstractCommand {
protected: protected:
SharedHandle<Request> _proxyRequest;
SharedHandle<HttpConnection> httpConnection; SharedHandle<HttpConnection> httpConnection;
virtual bool executeInternal(); virtual bool executeInternal();
@ -52,7 +54,9 @@ public:
const SharedHandle<Request>& req, const SharedHandle<Request>& req,
RequestGroup* requestGroup, RequestGroup* requestGroup,
DownloadEngine* e, DownloadEngine* e,
const SharedHandle<Request>& proxyRequest,
const SharedHandle<SocketCore>& s); const SharedHandle<SocketCore>& s);
virtual ~AbstractProxyRequestCommand(); virtual ~AbstractProxyRequestCommand();
virtual Command* getNextCommand() = 0; virtual Command* getNextCommand() = 0;

View File

@ -69,12 +69,6 @@ AuthConfigFactory::createAuthConfig(const RequestHandle& request) const
} }
} }
AuthConfigHandle
AuthConfigFactory::createAuthConfigForHttpProxy(const RequestHandle& request) const
{
return createHttpProxyAuthResolver()->resolveAuthConfig(request->getHost());
}
AuthConfigHandle AuthConfigHandle
AuthConfigFactory::createAuthConfig(const std::string& user, const std::string& password) const AuthConfigFactory::createAuthConfig(const std::string& user, const std::string& password) const
{ {
@ -118,20 +112,6 @@ AuthResolverHandle AuthConfigFactory::createFtpAuthResolver() const
return resolver; return resolver;
} }
AuthResolverHandle AuthConfigFactory::createHttpProxyAuthResolver() const
{
AbstractAuthResolverHandle resolver;
if(true || _option->getAsBool(PREF_NO_NETRC)) {
resolver.reset(new DefaultAuthResolver());
} else {
NetrcAuthResolverHandle authResolver(new NetrcAuthResolver());
authResolver->setNetrc(_netrc);
resolver = authResolver;
}
resolver->setUserDefinedAuthConfig(createAuthConfig(_option->get(PREF_HTTP_PROXY_USER), _option->get(PREF_HTTP_PROXY_PASSWD)));
return resolver;
}
void AuthConfigFactory::setNetrc(const NetrcHandle& netrc) void AuthConfigFactory::setNetrc(const NetrcHandle& netrc)
{ {
_netrc = netrc; _netrc = netrc;

View File

@ -61,8 +61,6 @@ private:
SharedHandle<AuthResolver> createHttpAuthResolver() const; SharedHandle<AuthResolver> createHttpAuthResolver() const;
SharedHandle<AuthResolver> createHttpProxyAuthResolver() const;
SharedHandle<AuthResolver> createFtpAuthResolver() const; SharedHandle<AuthResolver> createFtpAuthResolver() const;
public: public:
@ -74,9 +72,6 @@ public:
SharedHandle<AuthConfig> createAuthConfig SharedHandle<AuthConfig> createAuthConfig
(const SharedHandle<Request>& request) const; (const SharedHandle<Request>& request) const;
SharedHandle<AuthConfig> createAuthConfigForHttpProxy
(const SharedHandle<Request>& request) const;
void setNetrc(const SharedHandle<Netrc>& netrc); void setNetrc(const SharedHandle<Netrc>& netrc);
static const std::string ANONYMOUS; static const std::string ANONYMOUS;

View File

@ -33,6 +33,9 @@
*/ */
/* copyright --> */ /* copyright --> */
#include "FtpFinishDownloadCommand.h" #include "FtpFinishDownloadCommand.h"
#include <map>
#include "Request.h" #include "Request.h"
#include "DownloadEngine.h" #include "DownloadEngine.h"
#include "prefs.h" #include "prefs.h"
@ -44,7 +47,6 @@
#include "SocketCore.h" #include "SocketCore.h"
#include "RequestGroup.h" #include "RequestGroup.h"
#include "Logger.h" #include "Logger.h"
#include <map>
namespace aria2 { namespace aria2 {
@ -82,8 +84,7 @@ bool FtpFinishDownloadCommand::execute()
if(status != 226) { if(status != 226) {
throw DlAbortEx(StringFormat(EX_BAD_STATUS, status).str()); throw DlAbortEx(StringFormat(EX_BAD_STATUS, status).str());
} }
if(!e->option->getAsBool(PREF_HTTP_PROXY_ENABLED) && if(!isProxyDefined() && e->option->getAsBool(PREF_FTP_REUSE_CONNECTION)) {
e->option->getAsBool(PREF_FTP_REUSE_CONNECTION)) {
std::pair<std::string, uint16_t> peerInfo; std::pair<std::string, uint16_t> peerInfo;
socket->getPeerInfo(peerInfo); socket->getPeerInfo(peerInfo);
std::map<std::string, std::string> options; std::map<std::string, std::string> options;

View File

@ -33,6 +33,9 @@
*/ */
/* copyright --> */ /* copyright --> */
#include "FtpInitiateConnectionCommand.h" #include "FtpInitiateConnectionCommand.h"
#include <map>
#include "DownloadEngine.h" #include "DownloadEngine.h"
#include "Option.h" #include "Option.h"
#include "Request.h" #include "Request.h"
@ -47,7 +50,6 @@
#include "prefs.h" #include "prefs.h"
#include "HttpConnection.h" #include "HttpConnection.h"
#include "Socket.h" #include "Socket.h"
#include <map>
namespace aria2 { namespace aria2 {
@ -61,22 +63,28 @@ FtpInitiateConnectionCommand::FtpInitiateConnectionCommand
FtpInitiateConnectionCommand::~FtpInitiateConnectionCommand() {} FtpInitiateConnectionCommand::~FtpInitiateConnectionCommand() {}
Command* FtpInitiateConnectionCommand::createNextCommand Command* FtpInitiateConnectionCommand::createNextCommand
(const std::deque<std::string>& resolvedAddresses) (const std::deque<std::string>& resolvedAddresses,
const SharedHandle<Request>& proxyRequest)
{ {
Command* command; Command* command;
if(useHTTPProxy()) { if(!proxyRequest.isNull()) {
logger->info(MSG_CONNECTING_TO_SERVER, cuid, logger->info(MSG_CONNECTING_TO_SERVER, cuid,
e->option->get(PREF_HTTP_PROXY_HOST).c_str(), proxyRequest->getHost().c_str(), proxyRequest->getPort());
e->option->getAsInt(PREF_HTTP_PROXY_PORT));
socket.reset(new SocketCore()); socket.reset(new SocketCore());
socket->establishConnection(resolvedAddresses.front(), socket->establishConnection(resolvedAddresses.front(),
e->option->getAsInt(PREF_HTTP_PROXY_PORT)); proxyRequest->getPort());
if(useHTTPProxyGet()) { if(e->option->get(PREF_HTTP_PROXY_METHOD) == V_GET) {
SharedHandle<HttpConnection> hc(new HttpConnection(cuid, socket, e->option)); SharedHandle<HttpConnection> hc
command = new HttpRequestCommand(cuid, req, _requestGroup, hc, e, socket); (new HttpConnection(cuid, socket, e->option));
} else if(useHTTPProxyConnect()) {
command = new FtpTunnelRequestCommand(cuid, req, _requestGroup, e, socket); HttpRequestCommand* c =
new HttpRequestCommand(cuid, req, _requestGroup, hc, e, socket);
c->setProxyRequest(proxyRequest);
command = c;
} else if(e->option->get(PREF_HTTP_PROXY_METHOD) == V_TUNNEL) {
command = new FtpTunnelRequestCommand(cuid, req, _requestGroup, e,
proxyRequest, socket);
} else { } else {
// TODO // TODO
throw DlAbortEx("ERROR"); throw DlAbortEx("ERROR");
@ -101,12 +109,4 @@ Command* FtpInitiateConnectionCommand::createNextCommand
return command; return command;
} }
bool FtpInitiateConnectionCommand::useHTTPProxyGet() const {
return useHTTPProxy() && e->option->get(PREF_FTP_VIA_HTTP_PROXY) == V_GET;
}
bool FtpInitiateConnectionCommand::useHTTPProxyConnect() const {
return useHTTPProxy() && e->option->get(PREF_FTP_VIA_HTTP_PROXY) == V_TUNNEL;
}
} // namespace aria2 } // namespace aria2

View File

@ -40,12 +40,10 @@
namespace aria2 { namespace aria2 {
class FtpInitiateConnectionCommand : public InitiateConnectionCommand { class FtpInitiateConnectionCommand : public InitiateConnectionCommand {
private:
bool useHTTPProxyGet() const;
bool useHTTPProxyConnect() const;
protected: protected:
virtual Command* createNextCommand virtual Command* createNextCommand
(const std::deque<std::string>& resolvedAddresses); (const std::deque<std::string>& resolvedAddresses,
const SharedHandle<Request>& proxyRequest);
public: public:
FtpInitiateConnectionCommand(int cuid, const SharedHandle<Request>& req, FtpInitiateConnectionCommand(int cuid, const SharedHandle<Request>& req,
RequestGroup* requestGroup, DownloadEngine* e); RequestGroup* requestGroup, DownloadEngine* e);

View File

@ -618,8 +618,7 @@ bool FtpNegotiationCommand::processSequence(const SegmentHandle& segment) {
void FtpNegotiationCommand::poolConnection() const void FtpNegotiationCommand::poolConnection() const
{ {
if(!e->option->getAsBool(PREF_HTTP_PROXY_ENABLED) && if(!isProxyDefined() && e->option->getAsBool(PREF_FTP_REUSE_CONNECTION)) {
e->option->getAsBool(PREF_FTP_REUSE_CONNECTION)) {
std::pair<std::string, uint16_t> peerInfo; std::pair<std::string, uint16_t> peerInfo;
socket->getPeerInfo(peerInfo); socket->getPeerInfo(peerInfo);
std::map<std::string, std::string> options; std::map<std::string, std::string> options;

View File

@ -39,12 +39,15 @@
namespace aria2 { namespace aria2 {
FtpTunnelRequestCommand::FtpTunnelRequestCommand(int cuid, FtpTunnelRequestCommand::FtpTunnelRequestCommand
const RequestHandle& req, (int cuid,
RequestGroup* requestGroup, const RequestHandle& req,
DownloadEngine* e, RequestGroup* requestGroup,
const SocketHandle& s) DownloadEngine* e,
:AbstractProxyRequestCommand(cuid, req, requestGroup, e, s) {} const SharedHandle<Request>& proxyRequest,
const SocketHandle& s)
:
AbstractProxyRequestCommand(cuid, req, requestGroup, e, proxyRequest, s) {}
FtpTunnelRequestCommand::~FtpTunnelRequestCommand() {} FtpTunnelRequestCommand::~FtpTunnelRequestCommand() {}

View File

@ -47,6 +47,7 @@ public:
const SharedHandle<Request>& req, const SharedHandle<Request>& req,
RequestGroup* requestGroup, RequestGroup* requestGroup,
DownloadEngine* e, DownloadEngine* e,
const SharedHandle<Request>& proxyRequest,
const SharedHandle<SocketCore>& s); const SharedHandle<SocketCore>& s);
virtual ~FtpTunnelRequestCommand(); virtual ~FtpTunnelRequestCommand();

View File

@ -63,7 +63,7 @@ bool HttpDownloadCommand::prepareForNextSegment() {
e->commands.push_back(command); e->commands.push_back(command);
return true; return true;
} else { } else {
if(!e->option->getAsBool(PREF_HTTP_PROXY_ENABLED)) { if(!isProxyDefined()) {
if(req->isPipeliningEnabled() || if(req->isPipeliningEnabled() ||
(req->isKeepAliveEnabled() && (req->isKeepAliveEnabled() &&
((!_transferEncodingDecoder.isNull() && ((!_transferEncodingDecoder.isNull() &&

View File

@ -46,6 +46,7 @@
#include "Socket.h" #include "Socket.h"
#include "message.h" #include "message.h"
#include "prefs.h" #include "prefs.h"
#include "A2STR.h"
namespace aria2 { namespace aria2 {
@ -59,22 +60,25 @@ HttpInitiateConnectionCommand::HttpInitiateConnectionCommand
HttpInitiateConnectionCommand::~HttpInitiateConnectionCommand() {} HttpInitiateConnectionCommand::~HttpInitiateConnectionCommand() {}
Command* HttpInitiateConnectionCommand::createNextCommand Command* HttpInitiateConnectionCommand::createNextCommand
(const std::deque<std::string>& resolvedAddresses) (const std::deque<std::string>& resolvedAddresses,
const SharedHandle<Request>& proxyRequest)
{ {
Command* command; Command* command;
if(useHTTPProxy()) { if(!proxyRequest.isNull()) {
logger->info(MSG_CONNECTING_TO_SERVER, cuid, logger->info(MSG_CONNECTING_TO_SERVER, cuid,
e->option->get(PREF_HTTP_PROXY_HOST).c_str(), proxyRequest->getHost().c_str(), proxyRequest->getPort());
e->option->getAsInt(PREF_HTTP_PROXY_PORT));
socket.reset(new SocketCore()); socket.reset(new SocketCore());
socket->establishConnection(resolvedAddresses.front(), socket->establishConnection(resolvedAddresses.front(),
e->option->getAsInt(PREF_HTTP_PROXY_PORT)); proxyRequest->getPort());
if(useProxyTunnel()) { if(useProxyTunnel()) {
command = new HttpProxyRequestCommand(cuid, req, _requestGroup, e, socket); command = new HttpProxyRequestCommand(cuid, req, _requestGroup, e,
proxyRequest, socket);
} else if(useProxyGet()) { } else if(useProxyGet()) {
SharedHandle<HttpConnection> httpConnection(new HttpConnection(cuid, socket, e->option)); SharedHandle<HttpConnection> httpConnection(new HttpConnection(cuid, socket, e->option));
command = new HttpRequestCommand(cuid, req, _requestGroup, HttpRequestCommand* c = new HttpRequestCommand(cuid, req, _requestGroup,
httpConnection, e, socket); httpConnection, e, socket);
c->setProxyRequest(proxyRequest);
command = c;
} else { } else {
// TODO // TODO
throw DlAbortEx("ERROR"); throw DlAbortEx("ERROR");

View File

@ -45,7 +45,8 @@ private:
bool useProxyTunnel() const; bool useProxyTunnel() const;
protected: protected:
virtual Command* createNextCommand virtual Command* createNextCommand
(const std::deque<std::string>& resolvedAddresses); (const std::deque<std::string>& resolvedAddresses,
const SharedHandle<Request>& proxyRequest);
public: public:
HttpInitiateConnectionCommand(int cuid, const SharedHandle<Request>& req, HttpInitiateConnectionCommand(int cuid, const SharedHandle<Request>& req,
RequestGroup* requestGroup, RequestGroup* requestGroup,

View File

@ -39,12 +39,15 @@
namespace aria2 { namespace aria2 {
HttpProxyRequestCommand::HttpProxyRequestCommand(int cuid, HttpProxyRequestCommand::HttpProxyRequestCommand
const RequestHandle& req, (int cuid,
RequestGroup* requestGroup, const RequestHandle& req,
DownloadEngine* e, RequestGroup* requestGroup,
const SocketHandle& s) DownloadEngine* e,
:AbstractProxyRequestCommand(cuid, req, requestGroup, e, s) {} const SharedHandle<Request>& proxyRequest,
const SocketHandle& s)
:
AbstractProxyRequestCommand(cuid, req, requestGroup, e, proxyRequest, s) {}
HttpProxyRequestCommand::~HttpProxyRequestCommand() {} HttpProxyRequestCommand::~HttpProxyRequestCommand() {}

View File

@ -47,6 +47,7 @@ public:
const SharedHandle<Request>& req, const SharedHandle<Request>& req,
RequestGroup* requestGroup, RequestGroup* requestGroup,
DownloadEngine* e, DownloadEngine* e,
const SharedHandle<Request>& proxyRequest,
const SharedHandle<SocketCore>& s); const SharedHandle<SocketCore>& s);
virtual ~HttpProxyRequestCommand(); virtual ~HttpProxyRequestCommand();

View File

@ -55,8 +55,6 @@ namespace aria2 {
const std::string HttpRequest::USER_AGENT("aria2"); const std::string HttpRequest::USER_AGENT("aria2");
HttpRequest::HttpRequest():entityLength(0), HttpRequest::HttpRequest():entityLength(0),
proxyEnabled(false),
proxyAuthEnabled(false),
_contentEncodingEnabled(true), _contentEncodingEnabled(true),
userAgent(USER_AGENT) userAgent(USER_AGENT)
{} {}
@ -139,7 +137,7 @@ std::string HttpRequest::createRequest() const
SharedHandle<AuthConfig> authConfig = SharedHandle<AuthConfig> authConfig =
_authConfigFactory->createAuthConfig(request); _authConfigFactory->createAuthConfig(request);
std::string requestLine = "GET "; std::string requestLine = "GET ";
if(getProtocol() == Request::PROTO_FTP || proxyEnabled) { if(!_proxyRequest.isNull()) {
if(getProtocol() == Request::PROTO_FTP && if(getProtocol() == Request::PROTO_FTP &&
request->getUsername().empty() && !authConfig->getUser().empty()) { request->getUsername().empty() && !authConfig->getUser().empty()) {
// Insert user into URI, like ftp://USER@host/ // Insert user into URI, like ftp://USER@host/
@ -196,14 +194,14 @@ std::string HttpRequest::createRequest() const
} }
requestLine += "\r\n"; requestLine += "\r\n";
} }
if(proxyEnabled) { if(!_proxyRequest.isNull()) {
if(request->isKeepAliveEnabled() || request->isPipeliningEnabled()) { if(request->isKeepAliveEnabled() || request->isPipeliningEnabled()) {
requestLine += "Proxy-Connection: Keep-Alive\r\n"; requestLine += "Proxy-Connection: Keep-Alive\r\n";
} else { } else {
requestLine += "Proxy-Connection: close\r\n"; requestLine += "Proxy-Connection: close\r\n";
} }
} }
if(proxyEnabled && proxyAuthEnabled) { if(!_proxyRequest.isNull() && !_proxyRequest->getUsername().empty()) {
requestLine += getProxyAuthString(); requestLine += getProxyAuthString();
} }
if(!authConfig->getUser().empty()) { if(!authConfig->getUser().empty()) {
@ -241,6 +239,7 @@ std::string HttpRequest::createRequest() const
std::string HttpRequest::createProxyRequest() const std::string HttpRequest::createProxyRequest() const
{ {
assert(!_proxyRequest.isNull());
std::string requestLine = std::string requestLine =
std::string("CONNECT ")+getHost()+":"+Util::uitos(getPort())+ std::string("CONNECT ")+getHost()+":"+Util::uitos(getPort())+
std::string(" HTTP/1.1\r\n")+ std::string(" HTTP/1.1\r\n")+
@ -251,7 +250,7 @@ std::string HttpRequest::createProxyRequest() const
}else { }else {
requestLine += "Proxy-Connection: close\r\n"; requestLine += "Proxy-Connection: close\r\n";
} }
if(proxyAuthEnabled) { if(!_proxyRequest->getUsername().empty()) {
requestLine += getProxyAuthString(); requestLine += getProxyAuthString();
} }
requestLine += "\r\n"; requestLine += "\r\n";
@ -261,8 +260,9 @@ std::string HttpRequest::createProxyRequest() const
std::string HttpRequest::getProxyAuthString() const std::string HttpRequest::getProxyAuthString() const
{ {
return "Proxy-Authorization: Basic "+ return "Proxy-Authorization: Basic "+
Base64::encode(_authConfigFactory->createAuthConfigForHttpProxy(request)-> Base64::encode(_proxyRequest->getUsername()+":"+
getAuthText())+"\r\n"; _proxyRequest->getPassword())
+"\r\n";
} }
void HttpRequest::enableContentEncoding() void HttpRequest::enableContentEncoding()
@ -287,14 +287,6 @@ void HttpRequest::addAcceptType(const std::string& type)
_acceptTypes.push_back(type); _acceptTypes.push_back(type);
} }
void HttpRequest::configure(const Option* option)
{
proxyEnabled =
option->getAsBool(PREF_HTTP_PROXY_ENABLED) &&
option->get(PREF_HTTP_PROXY_METHOD) == V_GET;
proxyAuthEnabled = option->getAsBool(PREF_HTTP_PROXY_AUTH_ENABLED);
}
const std::string& HttpRequest::getPreviousURI() const const std::string& HttpRequest::getPreviousURI() const
{ {
return request->getPreviousUrl(); return request->getPreviousUrl();
@ -357,4 +349,9 @@ void HttpRequest::setAuthConfigFactory
_authConfigFactory = factory; _authConfigFactory = factory;
} }
void HttpRequest::setProxyRequest(const SharedHandle<Request>& proxyRequest)
{
_proxyRequest = proxyRequest;
}
} // namespace aria2 } // namespace aria2

View File

@ -62,10 +62,6 @@ private:
uint64_t entityLength; uint64_t entityLength;
bool proxyEnabled;
bool proxyAuthEnabled;
bool _contentEncodingEnabled; bool _contentEncodingEnabled;
std::string userAgent; std::string userAgent;
@ -78,6 +74,8 @@ private:
SharedHandle<AuthConfigFactory> _authConfigFactory; SharedHandle<AuthConfigFactory> _authConfigFactory;
SharedHandle<Request> _proxyRequest;
std::string getHostText(const std::string& host, uint16_t port) const; std::string getHostText(const std::string& host, uint16_t port) const;
std::string getProxyAuthString() const; std::string getProxyAuthString() const;
@ -147,25 +145,6 @@ public:
*/ */
std::string createProxyRequest() const; std::string createProxyRequest() const;
/**
* Configures this object with option.
* Following values are evaluated:
* PREF_HTTP_PROXY_ENABLED,
* PREF_HTTP_PROXY_METHOD, PREF_HTTP_PROXY_AUTH_ENABLED,
* The evaluation results are stored in instance variables.
*/
void configure(const Option* option);
void setProxyEnabled(bool proxyEnabled)
{
this->proxyEnabled = proxyEnabled;
}
void setProxyAuthEnabled(bool proxyAuthEnabled)
{
this->proxyAuthEnabled = proxyAuthEnabled;
}
void enableContentEncoding(); void enableContentEncoding();
void disableContentEncoding(); void disableContentEncoding();
@ -191,6 +170,12 @@ public:
SharedHandle<CookieStorage> getCookieStorage() const; SharedHandle<CookieStorage> getCookieStorage() const;
void setAuthConfigFactory(const SharedHandle<AuthConfigFactory>& factory); void setAuthConfigFactory(const SharedHandle<AuthConfigFactory>& factory);
/*
* To use proxy, pass proxy string to Request::setUrl() and set it this
* object.
*/
void setProxyRequest(const SharedHandle<Request>& proxyRequest);
}; };
typedef SharedHandle<HttpRequest> HttpRequestHandle; typedef SharedHandle<HttpRequest> HttpRequestHandle;

View File

@ -79,7 +79,8 @@ createHttpRequest(const SharedHandle<Request>& req,
const Option* option, const Option* option,
const RequestGroup* rg, const RequestGroup* rg,
const SharedHandle<CookieStorage>& cookieStorage, const SharedHandle<CookieStorage>& cookieStorage,
const SharedHandle<AuthConfigFactory>& authConfigFactory) const SharedHandle<AuthConfigFactory>& authConfigFactory,
const SharedHandle<Request>& proxyRequest)
{ {
HttpRequestHandle httpRequest(new HttpRequest()); HttpRequestHandle httpRequest(new HttpRequest());
httpRequest->setUserAgent(option->get(PREF_USER_AGENT)); httpRequest->setUserAgent(option->get(PREF_USER_AGENT));
@ -89,6 +90,7 @@ createHttpRequest(const SharedHandle<Request>& req,
httpRequest->addHeader(option->get(PREF_HEADER)); httpRequest->addHeader(option->get(PREF_HEADER));
httpRequest->setCookieStorage(cookieStorage); httpRequest->setCookieStorage(cookieStorage);
httpRequest->setAuthConfigFactory(authConfigFactory); httpRequest->setAuthConfigFactory(authConfigFactory);
httpRequest->setProxyRequest(proxyRequest);
if(!rg->getAcceptFeatures().empty()) { if(!rg->getAcceptFeatures().empty()) {
const std::deque<std::string>& acceptFeatures = rg->getAcceptFeatures(); const std::deque<std::string>& acceptFeatures = rg->getAcceptFeatures();
std::string acceptFeaturesHeader = "Accept-Features: "; std::string acceptFeaturesHeader = "Accept-Features: ";
@ -98,7 +100,6 @@ createHttpRequest(const SharedHandle<Request>& req,
} }
httpRequest->addAcceptType(rg->getAcceptTypes().begin(), httpRequest->addAcceptType(rg->getAcceptTypes().begin(),
rg->getAcceptTypes().end()); rg->getAcceptTypes().end());
httpRequest->configure(option);
return httpRequest; return httpRequest;
} }
@ -123,7 +124,8 @@ bool HttpRequestCommand::executeInternal() {
_requestGroup->getTotalLength(), e->option, _requestGroup->getTotalLength(), e->option,
_requestGroup, _requestGroup,
e->getCookieStorage(), e->getCookieStorage(),
e->getAuthConfigFactory())); e->getAuthConfigFactory(),
_proxyRequest));
_httpConnection->sendRequest(httpRequest); _httpConnection->sendRequest(httpRequest);
} else { } else {
for(Segments::iterator itr = _segments.begin(); itr != _segments.end(); ++itr) { for(Segments::iterator itr = _segments.begin(); itr != _segments.end(); ++itr) {
@ -134,7 +136,8 @@ bool HttpRequestCommand::executeInternal() {
_requestGroup->getTotalLength(), e->option, _requestGroup->getTotalLength(), e->option,
_requestGroup, _requestGroup,
e->getCookieStorage(), e->getCookieStorage(),
e->getAuthConfigFactory())); e->getAuthConfigFactory(),
_proxyRequest));
_httpConnection->sendRequest(httpRequest); _httpConnection->sendRequest(httpRequest);
} }
} }
@ -155,4 +158,10 @@ bool HttpRequestCommand::executeInternal() {
} }
} }
void HttpRequestCommand::setProxyRequest
(const SharedHandle<Request>& proxyRequest)
{
_proxyRequest = proxyRequest;
}
} // namespace aria2 } // namespace aria2

View File

@ -44,6 +44,8 @@ class SocketCore;
class HttpRequestCommand:public AbstractCommand { class HttpRequestCommand:public AbstractCommand {
private: private:
SharedHandle<Request> _proxyRequest;
SharedHandle<HttpConnection> _httpConnection; SharedHandle<HttpConnection> _httpConnection;
protected: protected:
virtual bool executeInternal(); virtual bool executeInternal();
@ -55,6 +57,8 @@ public:
DownloadEngine* e, DownloadEngine* e,
const SharedHandle<SocketCore>& s); const SharedHandle<SocketCore>& s);
virtual ~HttpRequestCommand(); virtual ~HttpRequestCommand();
void setProxyRequest(const SharedHandle<Request>& proxyRequest);
}; };
} // namespace aria2 } // namespace aria2

View File

@ -137,8 +137,7 @@ bool HttpSkipResponseCommand::executeInternal()
void HttpSkipResponseCommand::poolConnection() const void HttpSkipResponseCommand::poolConnection() const
{ {
if(!e->option->getAsBool(PREF_HTTP_PROXY_ENABLED) && if(!isProxyDefined() && req->supportsPersistentConnection()) {
req->supportsPersistentConnection()) {
std::pair<std::string, uint16_t> peerInfo; std::pair<std::string, uint16_t> peerInfo;
socket->getPeerInfo(peerInfo); socket->getPeerInfo(peerInfo);
e->poolSocket(peerInfo.first, peerInfo.second, socket); e->poolSocket(peerInfo.first, peerInfo.second, socket);

View File

@ -62,10 +62,11 @@ InitiateConnectionCommand::~InitiateConnectionCommand() {}
bool InitiateConnectionCommand::executeInternal() { bool InitiateConnectionCommand::executeInternal() {
std::string hostname; std::string hostname;
if(useHTTPProxy()) { SharedHandle<Request> proxyRequest = createProxyRequest();
hostname = e->option->get(PREF_HTTP_PROXY_HOST); if(proxyRequest.isNull()) {
} else {
hostname = req->getHost(); hostname = req->getHost();
} else {
hostname = proxyRequest->getHost();
} }
std::deque<std::string> addrs; std::deque<std::string> addrs;
std::string ipaddr = e->findCachedIPAddress(hostname); std::string ipaddr = e->findCachedIPAddress(hostname);
@ -97,14 +98,9 @@ bool InitiateConnectionCommand::executeInternal() {
addrs.push_back(ipaddr); addrs.push_back(ipaddr);
} }
Command* command = createNextCommand(addrs); Command* command = createNextCommand(addrs, proxyRequest);
e->commands.push_back(command); e->commands.push_back(command);
return true; return true;
} }
bool InitiateConnectionCommand::useHTTPProxy() const
{
return e->option->getAsBool(PREF_HTTP_PROXY_ENABLED);
}
} // namespace aria2 } // namespace aria2

View File

@ -41,8 +41,6 @@ namespace aria2 {
class InitiateConnectionCommand : public AbstractCommand { class InitiateConnectionCommand : public AbstractCommand {
protected: protected:
bool useHTTPProxy() const;
/** /**
* Connect to the server. * Connect to the server.
* This method just send connection request to the server. * This method just send connection request to the server.
@ -52,7 +50,8 @@ protected:
virtual bool executeInternal(); virtual bool executeInternal();
virtual Command* createNextCommand virtual Command* createNextCommand
(const std::deque<std::string>& resolvedAddresses) = 0; (const std::deque<std::string>& resolvedAddresses,
const SharedHandle<Request>& proxyRequest) = 0;
public: public:
InitiateConnectionCommand(int cuid, const SharedHandle<Request>& req, InitiateConnectionCommand(int cuid, const SharedHandle<Request>& req,
RequestGroup* requestGroup, RequestGroup* requestGroup,

View File

@ -471,30 +471,6 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers()
op->addTag(TAG_HTTP); op->addTag(TAG_HTTP);
handlers.push_back(op); handlers.push_back(op);
} }
{
SharedHandle<OptionHandler> op(new HttpProxyOptionHandler
(PREF_HTTP_PROXY,
TEXT_HTTP_PROXY,
NO_DEFAULT_VALUE,
PREF_HTTP_PROXY_HOST,
PREF_HTTP_PROXY_PORT));
op->addTag(TAG_HTTP);
handlers.push_back(op);
}
{
SharedHandle<OptionHandler> op(new DefaultOptionHandler
(PREF_HTTP_PROXY_USER,
TEXT_HTTP_PROXY_USER));
op->addTag(TAG_HTTP);
handlers.push_back(op);
}
{
SharedHandle<OptionHandler> op(new DefaultOptionHandler
(PREF_HTTP_PROXY_PASSWD,
TEXT_HTTP_PROXY_PASSWD));
op->addTag(TAG_HTTP);
handlers.push_back(op);
}
{ {
SharedHandle<OptionHandler> op(new ParameterOptionHandler SharedHandle<OptionHandler> op(new ParameterOptionHandler
(PREF_HTTP_PROXY_METHOD, (PREF_HTTP_PROXY_METHOD,
@ -588,15 +564,6 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers()
op->addTag(TAG_FTP); op->addTag(TAG_FTP);
handlers.push_back(op); handlers.push_back(op);
} }
{
SharedHandle<OptionHandler> op(new ParameterOptionHandler
(PREF_FTP_VIA_HTTP_PROXY,
TEXT_FTP_VIA_HTTP_PROXY,
V_TUNNEL,
V_GET, V_TUNNEL));
op->addTag(TAG_FTP);
handlers.push_back(op);
}
{ {
SharedHandle<OptionHandler> op(new DefaultOptionHandler SharedHandle<OptionHandler> op(new DefaultOptionHandler
(PREF_NETRC_PATH, (PREF_NETRC_PATH,
@ -615,6 +582,40 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers()
op->addTag(TAG_HTTP); op->addTag(TAG_HTTP);
handlers.push_back(op); handlers.push_back(op);
} }
// Proxy options
{
SharedHandle<OptionHandler> op(new HttpProxyOptionHandler
(PREF_HTTP_PROXY,
TEXT_HTTP_PROXY,
NO_DEFAULT_VALUE));
op->addTag(TAG_HTTP);
handlers.push_back(op);
}
{
SharedHandle<OptionHandler> op(new HttpProxyOptionHandler
(PREF_HTTPS_PROXY,
TEXT_HTTPS_PROXY,
NO_DEFAULT_VALUE));
op->addTag(TAG_HTTP);
handlers.push_back(op);
}
{
SharedHandle<OptionHandler> op(new HttpProxyOptionHandler
(PREF_FTP_PROXY,
TEXT_FTP_PROXY,
NO_DEFAULT_VALUE));
op->addTag(TAG_FTP);
handlers.push_back(op);
}
{
SharedHandle<OptionHandler> op(new HttpProxyOptionHandler
(PREF_ALL_PROXY,
TEXT_ALL_PROXY,
NO_DEFAULT_VALUE));
op->addTag(TAG_HTTP);
op->addTag(TAG_FTP);
handlers.push_back(op);
}
// BitTorrent/Metalink Options // BitTorrent/Metalink Options
{ {
SharedHandle<OptionHandler> op(new IntegerRangeOptionHandler SharedHandle<OptionHandler> op(new IntegerRangeOptionHandler

View File

@ -36,6 +36,14 @@
#define _D_OPTION_HANDLER_IMPL_H_ #define _D_OPTION_HANDLER_IMPL_H_
#include "OptionHandler.h" #include "OptionHandler.h"
#include <cstdio>
#include <utility>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iterator>
#include "NameMatchOptionHandler.h" #include "NameMatchOptionHandler.h"
#include "Util.h" #include "Util.h"
#include "FatalException.h" #include "FatalException.h"
@ -43,12 +51,7 @@
#include "Option.h" #include "Option.h"
#include "StringFormat.h" #include "StringFormat.h"
#include "A2STR.h" #include "A2STR.h"
#include <cstdio> #include "Request.h"
#include <utility>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iterator>
namespace aria2 { namespace aria2 {
@ -439,23 +442,36 @@ public:
} }
}; };
class HttpProxyOptionHandler : public HostPortOptionHandler { class HttpProxyOptionHandler : public NameMatchOptionHandler {
public: public:
HttpProxyOptionHandler(const std::string& optName, HttpProxyOptionHandler(const std::string& optName,
const std::string& description, const std::string& description,
const std::string& defaultValue, const std::string& defaultValue)
const std::string& hostOptionName, :
const std::string& portOptionName): NameMatchOptionHandler(optName, description, defaultValue)
HostPortOptionHandler(optName, description, defaultValue,
hostOptionName, portOptionName)
{} {}
virtual ~HttpProxyOptionHandler() {} virtual ~HttpProxyOptionHandler() {}
virtual void parseArg(Option* option, const std::string& optarg) virtual void parseArg(Option* option, const std::string& optarg)
{ {
HostPortOptionHandler::parseArg(option, optarg); Request req;
option->put(PREF_HTTP_PROXY_ENABLED, V_TRUE); std::string url;
if(Util::startsWith(optarg, "http://")) {
url = optarg;
} else {
url = "http://"+optarg;
}
if(req.setUrl(url)) {
option->put(_optName, url);
} else {
throw FatalException(_("unrecognized proxy format"));
}
}
virtual std::string createPossibleValuesString() const
{
return "[http://][USER:PASSWORD@]HOST[:PORT]";
} }
}; };

View File

@ -197,7 +197,11 @@ bool Request::parseUrl(const std::string& url) {
host = hostAndPort.first; host = hostAndPort.first;
if(hostAndPort.second != A2STR::NIL) { if(hostAndPort.second != A2STR::NIL) {
try { try {
port = Util::parseInt(hostAndPort.second); unsigned int tempPort = Util::parseUInt(hostAndPort.second);
if(65535 < tempPort) {
return false;
}
port = tempPort;
} catch(RecoverableException& e) { } catch(RecoverableException& e) {
return false; return false;
} }

View File

@ -107,8 +107,8 @@ Option* option_processing(int argc, char* const argv[])
{ PREF_HTTP_PROXY.c_str(), required_argument, &lopt, 1 }, { PREF_HTTP_PROXY.c_str(), required_argument, &lopt, 1 },
{ PREF_HTTP_USER.c_str(), required_argument, &lopt, 2 }, { PREF_HTTP_USER.c_str(), required_argument, &lopt, 2 },
{ PREF_HTTP_PASSWD.c_str(), required_argument, &lopt, 3 }, { PREF_HTTP_PASSWD.c_str(), required_argument, &lopt, 3 },
{ PREF_HTTP_PROXY_USER.c_str(), required_argument, &lopt, 4 }, { "http-proxy-user", required_argument, &lopt, 4 },
{ PREF_HTTP_PROXY_PASSWD.c_str(), required_argument, &lopt, 5 }, { "http-proxy-passwd", required_argument, &lopt, 5 },
{ PREF_HTTP_AUTH_SCHEME.c_str(), required_argument, &lopt, 6 }, { PREF_HTTP_AUTH_SCHEME.c_str(), required_argument, &lopt, 6 },
{ PREF_REFERER.c_str(), required_argument, &lopt, 7 }, { PREF_REFERER.c_str(), required_argument, &lopt, 7 },
{ PREF_RETRY_WAIT.c_str(), required_argument, &lopt, 8 }, { PREF_RETRY_WAIT.c_str(), required_argument, &lopt, 8 },
@ -116,7 +116,7 @@ Option* option_processing(int argc, char* const argv[])
{ PREF_FTP_PASSWD.c_str(), required_argument, &lopt, 10 }, { PREF_FTP_PASSWD.c_str(), required_argument, &lopt, 10 },
{ PREF_FTP_TYPE.c_str(), required_argument, &lopt, 11 }, { PREF_FTP_TYPE.c_str(), required_argument, &lopt, 11 },
{ PREF_FTP_PASV.c_str(), no_argument, NULL, 'p' }, { PREF_FTP_PASV.c_str(), no_argument, NULL, 'p' },
{ PREF_FTP_VIA_HTTP_PROXY.c_str(), required_argument, &lopt, 12 }, { "ftp-via-http-proxy", required_argument, &lopt, 12 },
{ PREF_HTTP_PROXY_METHOD.c_str(), required_argument, &lopt, 14 }, { PREF_HTTP_PROXY_METHOD.c_str(), required_argument, &lopt, 14 },
{ PREF_LOWEST_SPEED_LIMIT.c_str(), required_argument, &lopt, 200 }, { PREF_LOWEST_SPEED_LIMIT.c_str(), required_argument, &lopt, 200 },
{ PREF_MAX_DOWNLOAD_LIMIT.c_str(), required_argument, &lopt, 201 }, { PREF_MAX_DOWNLOAD_LIMIT.c_str(), required_argument, &lopt, 201 },
@ -161,6 +161,9 @@ Option* option_processing(int argc, char* const argv[])
{ PREF_CONNECT_TIMEOUT.c_str(), required_argument, &lopt, 224 }, { PREF_CONNECT_TIMEOUT.c_str(), required_argument, &lopt, 224 },
{ PREF_MAX_FILE_NOT_FOUND.c_str(), required_argument, &lopt, 225 }, { PREF_MAX_FILE_NOT_FOUND.c_str(), required_argument, &lopt, 225 },
{ PREF_AUTO_SAVE_INTERVAL.c_str(), required_argument, &lopt, 226 }, { PREF_AUTO_SAVE_INTERVAL.c_str(), required_argument, &lopt, 226 },
{ PREF_HTTPS_PROXY.c_str(), required_argument, &lopt, 227 },
{ PREF_FTP_PROXY.c_str(), required_argument, &lopt, 228 },
{ PREF_ALL_PROXY.c_str(), required_argument, &lopt, 229 },
#if defined ENABLE_BITTORRENT || defined ENABLE_METALINK #if defined ENABLE_BITTORRENT || defined ENABLE_METALINK
{ PREF_SHOW_FILES.c_str(), no_argument, NULL, 'S' }, { PREF_SHOW_FILES.c_str(), no_argument, NULL, 'S' },
{ PREF_SELECT_FILE.c_str(), required_argument, &lopt, 21 }, { PREF_SELECT_FILE.c_str(), required_argument, &lopt, 21 },
@ -221,11 +224,15 @@ Option* option_processing(int argc, char* const argv[])
cmdstream << PREF_HTTP_PASSWD << "=" << optarg << "\n"; cmdstream << PREF_HTTP_PASSWD << "=" << optarg << "\n";
break; break;
case 4: case 4:
cmdstream << PREF_HTTP_PROXY_USER << "=" << optarg << "\n"; std::cout << "--http-proxy-user was deprecated. See --http-proxy,"
break; << " --https-proxy, --ftp-proxy, --all-proxy options."
<< std::endl;
exit(EXIT_FAILURE);
case 5: case 5:
cmdstream << PREF_HTTP_PROXY_PASSWD << "=" << optarg << "\n"; std::cout << "--http-proxy-passwd was deprecated. See --http-proxy,"
break; << " --https-proxy, --ftp-proxy, --all-proxy options."
<< std::endl;
exit(EXIT_FAILURE);
case 6: case 6:
cmdstream << PREF_HTTP_AUTH_SCHEME << "=" << optarg << "\n"; cmdstream << PREF_HTTP_AUTH_SCHEME << "=" << optarg << "\n";
break; break;
@ -245,8 +252,10 @@ Option* option_processing(int argc, char* const argv[])
cmdstream << PREF_FTP_TYPE << "=" << optarg << "\n"; cmdstream << PREF_FTP_TYPE << "=" << optarg << "\n";
break; break;
case 12: case 12:
cmdstream << PREF_FTP_VIA_HTTP_PROXY << "=" << optarg << "\n"; std::cout << "--ftp-via-http-proxy was deprecated."
break; << " Use --http-proxy-method option instead."
<< std::endl;
exit(EXIT_FAILURE);
case 14: case 14:
cmdstream << PREF_HTTP_PROXY_METHOD << "=" << optarg << "\n"; cmdstream << PREF_HTTP_PROXY_METHOD << "=" << optarg << "\n";
break; break;
@ -409,6 +418,15 @@ Option* option_processing(int argc, char* const argv[])
case 226: case 226:
cmdstream << PREF_AUTO_SAVE_INTERVAL << "=" << optarg << "\n"; cmdstream << PREF_AUTO_SAVE_INTERVAL << "=" << optarg << "\n";
break; break;
case 227:
cmdstream << PREF_HTTPS_PROXY << "=" << optarg << "\n";
break;
case 228:
cmdstream << PREF_FTP_PROXY << "=" << optarg << "\n";
break;
case 229:
cmdstream << PREF_ALL_PROXY << "=" << optarg << "\n";
break;
} }
break; break;
} }
@ -545,9 +563,6 @@ Option* option_processing(int argc, char* const argv[])
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
if(op->defined(PREF_HTTP_PROXY_USER)) {
op->put(PREF_HTTP_PROXY_AUTH_ENABLED, V_TRUE);
}
if( if(
#ifdef ENABLE_BITTORRENT #ifdef ENABLE_BITTORRENT
!op->defined(PREF_TORRENT_FILE) && !op->defined(PREF_TORRENT_FILE) &&

View File

@ -155,10 +155,6 @@ const std::string PREF_FTP_PASSWD("ftp-passwd");
const std::string PREF_FTP_TYPE("ftp-type"); const std::string PREF_FTP_TYPE("ftp-type");
const std::string V_BINARY("binary"); const std::string V_BINARY("binary");
const std::string V_ASCII("ascii"); const std::string V_ASCII("ascii");
// values: get | tunnel
const std::string PREF_FTP_VIA_HTTP_PROXY("ftp-via-http-proxy");
const std::string V_GET("get");
const std::string V_TUNNEL("tunnel");
// values: true | false // values: true | false
const std::string PREF_FTP_PASV("ftp-pasv"); const std::string PREF_FTP_PASV("ftp-pasv");
// values: true | false // values: true | false
@ -186,19 +182,16 @@ const std::string PREF_MAX_HTTP_PIPELINING("max-http-pipelining");
const std::string PREF_HEADER("header"); const std::string PREF_HEADER("header");
/** /**
* HTTP proxy related preferences * Proxy related preferences
*/ */
const std::string PREF_HTTP_PROXY("http-proxy"); const std::string PREF_HTTP_PROXY("http-proxy");
const std::string PREF_HTTP_PROXY_USER("http-proxy-user"); const std::string PREF_HTTPS_PROXY("https-proxy");
const std::string PREF_HTTP_PROXY_PASSWD("http-proxy-passwd"); const std::string PREF_FTP_PROXY("ftp-proxy");
const std::string PREF_HTTP_PROXY_HOST("http-proxy-host"); const std::string PREF_ALL_PROXY("all-proxy");
const std::string PREF_HTTP_PROXY_PORT("http-proxy-port");
// values: get | tunnel // values: get | tunnel
const std::string PREF_HTTP_PROXY_METHOD("http-proxy-method"); const std::string PREF_HTTP_PROXY_METHOD("http-proxy-method");
// values: true | false const std::string V_GET("get");
const std::string PREF_HTTP_PROXY_ENABLED("http-proxy-enabled"); const std::string V_TUNNEL("tunnel");
// values: true | false
const std::string PREF_HTTP_PROXY_AUTH_ENABLED("http-proxy-auth-enabled");
/** /**
* BitTorrent related preferences * BitTorrent related preferences

View File

@ -159,10 +159,6 @@ extern const std::string PREF_FTP_PASSWD;
extern const std::string PREF_FTP_TYPE; extern const std::string PREF_FTP_TYPE;
extern const std::string V_BINARY; extern const std::string V_BINARY;
extern const std::string V_ASCII; extern const std::string V_ASCII;
// values: get | tunnel
extern const std::string PREF_FTP_VIA_HTTP_PROXY;
extern const std::string V_GET;
extern const std::string V_TUNNEL;
// values: true | false // values: true | false
extern const std::string PREF_FTP_PASV; extern const std::string PREF_FTP_PASV;
// values: true | false // values: true | false
@ -190,19 +186,16 @@ extern const std::string PREF_MAX_HTTP_PIPELINING;
extern const std::string PREF_HEADER; extern const std::string PREF_HEADER;
/**; /**;
* HTTP proxy related preferences * Proxy related preferences
*/ */
extern const std::string PREF_HTTP_PROXY; extern const std::string PREF_HTTP_PROXY;
extern const std::string PREF_HTTP_PROXY_USER; extern const std::string PREF_HTTPS_PROXY;
extern const std::string PREF_HTTP_PROXY_PASSWD; extern const std::string PREF_FTP_PROXY;
extern const std::string PREF_HTTP_PROXY_HOST; extern const std::string PREF_ALL_PROXY;
extern const std::string PREF_HTTP_PROXY_PORT;
// values: get | tunnel // values: get | tunnel
extern const std::string PREF_HTTP_PROXY_METHOD; extern const std::string PREF_HTTP_PROXY_METHOD;
// values: true | false extern const std::string V_GET;
extern const std::string PREF_HTTP_PROXY_ENABLED; extern const std::string V_TUNNEL;
// values: true | false
extern const std::string PREF_HTTP_PROXY_AUTH_ENABLED;
/** /**
* BitTorrent related preferences * BitTorrent related preferences

View File

@ -57,15 +57,28 @@ _(" -t, --timeout=SEC Set timeout in seconds.")
#define TEXT_MAX_TRIES \ #define TEXT_MAX_TRIES \
_(" -m, --max-tries=N Set number of tries. 0 means unlimited.") _(" -m, --max-tries=N Set number of tries. 0 means unlimited.")
#define TEXT_HTTP_PROXY \ #define TEXT_HTTP_PROXY \
_(" --http-proxy=HOST:PORT Use HTTP proxy server. This affects all URLs.") _(" --http-proxy=PROXY Use this proxy server for HTTP.\n"\
" See also --all-proxy option.\n"\
" This affects all URLs.")
#define TEXT_HTTPS_PROXY \
_(" --https-proxy=PROXY Use this proxy server for HTTPS.\n"\
" See also --all-proxy option.\n"\
" This affects all URLs.")
#define TEXT_FTP_PROXY \
_(" --ftp-proxy=PROXY Use this proxy server for FTP.\n"\
" See also --all-proxy option.\n"\
" This affects all URLs.")
#define TEXT_ALL_PROXY \
_(" --all-proxy=PROXY Use this proxy server in the all protocols.\n"\
" You can override this setting and specify a\n"\
" proxy server for particular proctol using\n"\
" --http-proxy, --https-proxy and --ftp-proxy\n"\
" options.\n"\
" This affects all URLs.")
#define TEXT_HTTP_USER \ #define TEXT_HTTP_USER \
_(" --http-user=USER Set HTTP user. This affects all URLs.") _(" --http-user=USER Set HTTP user. This affects all URLs.")
#define TEXT_HTTP_PASSWD \ #define TEXT_HTTP_PASSWD \
_(" --http-passwd=PASSWD Set HTTP password. This affects all URLs.") _(" --http-passwd=PASSWD Set HTTP password. This affects all URLs.")
#define TEXT_HTTP_PROXY_USER \
_(" --http-proxy-user=USER Set HTTP proxy user. This affects all URLs.")
#define TEXT_HTTP_PROXY_PASSWD \
_(" --http-proxy-passwd=PASSWD Set HTTP proxy password. This affects all URLs.")
#define TEXT_HTTP_PROXY_METHOD \ #define TEXT_HTTP_PROXY_METHOD \
_(" --http-proxy-method=METHOD Set the method to use in proxy request.") _(" --http-proxy-method=METHOD Set the method to use in proxy request.")
#define TEXT_HTTP_AUTH_SCHEME \ #define TEXT_HTTP_AUTH_SCHEME \
@ -81,8 +94,6 @@ _(" --ftp-passwd=PASSWD Set FTP password. This affects all URLs.")
_(" --ftp-type=TYPE Set FTP transfer type.") _(" --ftp-type=TYPE Set FTP transfer type.")
#define TEXT_FTP_PASV \ #define TEXT_FTP_PASV \
_(" -p, --ftp-pasv Use passive mode in FTP.") _(" -p, --ftp-pasv Use passive mode in FTP.")
#define TEXT_FTP_VIA_HTTP_PROXY \
_(" --ftp-via-http-proxy=METHOD Use HTTP proxy in FTP.")
#define TEXT_LOWEST_SPEED_LIMIT \ #define TEXT_LOWEST_SPEED_LIMIT \
_(" --lowest-speed-limit=SPEED Close connection if download speed is lower than\n"\ _(" --lowest-speed-limit=SPEED Close connection if download speed is lower than\n"\
" or equal to this value(bytes per sec).\n"\ " or equal to this value(bytes per sec).\n"\

View File

@ -1,10 +1,12 @@
#include "AuthConfigFactory.h" #include "AuthConfigFactory.h"
#include <cppunit/extensions/HelperMacros.h>
#include "Netrc.h" #include "Netrc.h"
#include "prefs.h" #include "prefs.h"
#include "Request.h" #include "Request.h"
#include "AuthConfig.h" #include "AuthConfig.h"
#include "Option.h" #include "Option.h"
#include <cppunit/extensions/HelperMacros.h>
namespace aria2 { namespace aria2 {
@ -12,13 +14,11 @@ class AuthConfigFactoryTest:public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(AuthConfigFactoryTest); CPPUNIT_TEST_SUITE(AuthConfigFactoryTest);
CPPUNIT_TEST(testCreateAuthConfig_http); CPPUNIT_TEST(testCreateAuthConfig_http);
CPPUNIT_TEST(testCreateAuthConfigForHttpProxy);
CPPUNIT_TEST(testCreateAuthConfig_ftp); CPPUNIT_TEST(testCreateAuthConfig_ftp);
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
public: public:
void testCreateAuthConfig_http(); void testCreateAuthConfig_http();
void testCreateAuthConfigForHttpProxy();
void testCreateAuthConfig_ftp(); void testCreateAuthConfig_ftp();
}; };
@ -71,32 +71,6 @@ void AuthConfigFactoryTest::testCreateAuthConfig_http()
factory.createAuthConfig(req)->getAuthText()); factory.createAuthConfig(req)->getAuthText());
} }
void AuthConfigFactoryTest::testCreateAuthConfigForHttpProxy()
{
SharedHandle<Request> req(new Request());
req->setUrl("http://localhost/download/aria2-1.0.0.tar.bz2");
// with Netrc
SharedHandle<Netrc> netrc(new Netrc());
netrc->addAuthenticator
(SharedHandle<Authenticator>(new DefaultAuthenticator("default", "defaultpassword", "defaultaccount")));
Option option;
option.put(PREF_NO_NETRC, V_FALSE);
AuthConfigFactory factory(&option);
factory.setNetrc(netrc);
// netrc is not used in http proxy auth
CPPUNIT_ASSERT_EQUAL(std::string(":"),
factory.createAuthConfigForHttpProxy(req)->getAuthText());
option.put(PREF_HTTP_PROXY_USER, "userDefinedUser");
option.put(PREF_HTTP_PROXY_PASSWD, "userDefinedPassword");
CPPUNIT_ASSERT_EQUAL(std::string("userDefinedUser:userDefinedPassword"),
factory.createAuthConfigForHttpProxy(req)->getAuthText());
}
void AuthConfigFactoryTest::testCreateAuthConfig_ftp() void AuthConfigFactoryTest::testCreateAuthConfig_ftp()
{ {
SharedHandle<Request> req(new Request()); SharedHandle<Request> req(new Request());

View File

@ -106,12 +106,6 @@ void HttpRequestTest::testCreateRequest()
{ {
SharedHandle<Piece> p; SharedHandle<Piece> p;
_option->put(PREF_HTTP_PROXY_ENABLED, V_FALSE);
_option->put(PREF_HTTP_PROXY_METHOD, V_TUNNEL);
_option->put(PREF_HTTP_PROXY_AUTH_ENABLED, V_FALSE);
_option->put(PREF_HTTP_PROXY_USER, "aria2proxyuser");
_option->put(PREF_HTTP_PROXY_PASSWD, "aria2proxypasswd");
SharedHandle<Request> request(new Request()); SharedHandle<Request> request(new Request());
request->supportsPersistentConnection(true); request->supportsPersistentConnection(true);
@ -225,8 +219,6 @@ void HttpRequestTest::testCreateRequest()
_option->put(PREF_HTTP_USER, "aria2user"); _option->put(PREF_HTTP_USER, "aria2user");
_option->put(PREF_HTTP_PASSWD, "aria2passwd"); _option->put(PREF_HTTP_PASSWD, "aria2passwd");
httpRequest.configure(_option.get());
expectedText = "GET /archives/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n" expectedText = "GET /archives/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n"
"User-Agent: aria2\r\n" "User-Agent: aria2\r\n"
"Accept: */*\r\n" "Accept: */*\r\n"
@ -240,41 +232,10 @@ void HttpRequestTest::testCreateRequest()
CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createRequest()); CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createRequest());
// enable http proxy auth // enable http proxy auth
_option->put(PREF_HTTP_PROXY_AUTH_ENABLED, V_TRUE); SharedHandle<Request> proxyRequest(new Request());
CPPUNIT_ASSERT(proxyRequest->setUrl
httpRequest.configure(_option.get()); ("http://aria2proxyuser:aria2proxypasswd@localhost:9000"));
httpRequest.setProxyRequest(proxyRequest);
expectedText = "GET /archives/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n"
"User-Agent: aria2\r\n"
"Accept: */*\r\n"
"Host: localhost:8080\r\n"
"Pragma: no-cache\r\n"
"Cache-Control: no-cache\r\n"
"Connection: close\r\n"
"Authorization: Basic YXJpYTJ1c2VyOmFyaWEycGFzc3dk\r\n"
"\r\n";
CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createRequest());
_option->put(PREF_HTTP_PROXY_ENABLED, V_TRUE);
httpRequest.configure(_option.get());
expectedText = "GET /archives/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n"
"User-Agent: aria2\r\n"
"Accept: */*\r\n"
"Host: localhost:8080\r\n"
"Pragma: no-cache\r\n"
"Cache-Control: no-cache\r\n"
"Connection: close\r\n"
"Authorization: Basic YXJpYTJ1c2VyOmFyaWEycGFzc3dk\r\n"
"\r\n";
CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createRequest());
_option->put(PREF_HTTP_PROXY_METHOD, V_GET);
httpRequest.configure(_option.get());
expectedText = "GET http://localhost:8080/archives/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n" expectedText = "GET http://localhost:8080/archives/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n"
"User-Agent: aria2\r\n" "User-Agent: aria2\r\n"
@ -308,9 +269,8 @@ void HttpRequestTest::testCreateRequest()
request->setPipeliningHint(false); request->setPipeliningHint(false);
_option->put(PREF_HTTP_PROXY_AUTH_ENABLED, V_FALSE); // turn off proxy auth
CPPUNIT_ASSERT(proxyRequest->setUrl("http://localhost:9000"));
httpRequest.configure(_option.get());
expectedText = "GET http://localhost:8080/archives/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n" expectedText = "GET http://localhost:8080/archives/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n"
"User-Agent: aria2\r\n" "User-Agent: aria2\r\n"
@ -328,17 +288,16 @@ void HttpRequestTest::testCreateRequest()
void HttpRequestTest::testCreateRequest_ftp() void HttpRequestTest::testCreateRequest_ftp()
{ {
_option->put(PREF_HTTP_PROXY_ENABLED, V_FALSE); _option->put(PREF_FTP_USER, "aria2user");
_option->put(PREF_HTTP_PROXY_METHOD, V_TUNNEL); _option->put(PREF_FTP_PASSWD, "aria2passwd");
_option->put(PREF_HTTP_PROXY_AUTH_ENABLED, V_FALSE);
_option->put(PREF_FTP_USER, "aria2user");
_option->put(PREF_FTP_PASSWD, "aria2passwd");
_option->put(PREF_HTTP_PROXY_USER, "aria2proxyuser");
_option->put(PREF_HTTP_PROXY_PASSWD, "aria2proxypasswd");
SharedHandle<Request> request(new Request()); SharedHandle<Request> request(new Request());
request->setUrl("ftp://localhost:8080/archives/aria2-1.0.0.tar.bz2"); request->setUrl("ftp://localhost:8080/archives/aria2-1.0.0.tar.bz2");
SharedHandle<Request> proxyRequest(new Request());
CPPUNIT_ASSERT(proxyRequest->setUrl
("http://localhost:9000"));
HttpRequest httpRequest; HttpRequest httpRequest;
SharedHandle<Piece> p(new Piece(0, 1024*1024)); SharedHandle<Piece> p(new Piece(0, 1024*1024));
SharedHandle<Segment> segment SharedHandle<Segment> segment
@ -347,8 +306,7 @@ void HttpRequestTest::testCreateRequest_ftp()
httpRequest.setRequest(request); httpRequest.setRequest(request);
httpRequest.setSegment(segment); httpRequest.setSegment(segment);
httpRequest.setAuthConfigFactory(_authConfigFactory); httpRequest.setAuthConfigFactory(_authConfigFactory);
httpRequest.setProxyRequest(proxyRequest);
httpRequest.configure(_option.get());
std::string expectedText = std::string expectedText =
"GET ftp://aria2user@localhost:8080/archives/aria2-1.0.0.tar.bz2" "GET ftp://aria2user@localhost:8080/archives/aria2-1.0.0.tar.bz2"
@ -359,17 +317,15 @@ void HttpRequestTest::testCreateRequest_ftp()
"Pragma: no-cache\r\n" "Pragma: no-cache\r\n"
"Cache-Control: no-cache\r\n" "Cache-Control: no-cache\r\n"
"Connection: close\r\n" "Connection: close\r\n"
"Proxy-Connection: close\r\n"
"Authorization: Basic YXJpYTJ1c2VyOmFyaWEycGFzc3dk\r\n" "Authorization: Basic YXJpYTJ1c2VyOmFyaWEycGFzc3dk\r\n"
"\r\n"; "\r\n";
CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createRequest()); CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createRequest());
// How to enable HTTP proxy authorization in FTP download via HTTP proxy // test proxy authorization
_option->put(PREF_HTTP_PROXY_ENABLED, V_TRUE); CPPUNIT_ASSERT(proxyRequest->setUrl
_option->put(PREF_HTTP_PROXY_METHOD, V_GET); ("http://aria2proxyuser:aria2proxypasswd@localhost:9000"));
_option->put(PREF_HTTP_PROXY_AUTH_ENABLED, V_TRUE);
httpRequest.configure(_option.get());
expectedText = expectedText =
"GET ftp://aria2user@localhost:8080/archives/aria2-1.0.0.tar.bz2" "GET ftp://aria2user@localhost:8080/archives/aria2-1.0.0.tar.bz2"
@ -386,7 +342,6 @@ void HttpRequestTest::testCreateRequest_ftp()
"\r\n"; "\r\n";
CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createRequest()); CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createRequest());
} }
void HttpRequestTest::testCreateRequest_with_cookie() void HttpRequestTest::testCreateRequest_with_cookie()
@ -502,10 +457,14 @@ void HttpRequestTest::testCreateProxyRequest()
SharedHandle<Piece> p(new Piece(0, 1024*1024)); SharedHandle<Piece> p(new Piece(0, 1024*1024));
SharedHandle<Segment> segment(new PiecedSegment(1024*1024, p)); SharedHandle<Segment> segment(new PiecedSegment(1024*1024, p));
SharedHandle<Request> proxyRequest(new Request());
CPPUNIT_ASSERT(proxyRequest->setUrl("http://localhost:9000"));
HttpRequest httpRequest; HttpRequest httpRequest;
httpRequest.setRequest(request); httpRequest.setRequest(request);
httpRequest.setSegment(segment); httpRequest.setSegment(segment);
httpRequest.setProxyRequest(proxyRequest);
request->supportsPersistentConnection(true); request->supportsPersistentConnection(true);
@ -539,6 +498,19 @@ void HttpRequestTest::testCreateProxyRequest()
"\r\n"; "\r\n";
CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createProxyRequest()); CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createProxyRequest());
// test proxy authorization
CPPUNIT_ASSERT(proxyRequest->setUrl
("http://aria2proxyuser:aria2proxypasswd@localhost:9000"));
expectedText = "CONNECT localhost:80 HTTP/1.1\r\n"
"User-Agent: aria2\r\n"
"Host: localhost:80\r\n"
"Proxy-Connection: Keep-Alive\r\n"
"Proxy-Authorization: Basic YXJpYTJwcm94eXVzZXI6YXJpYTJwcm94eXBhc3N3ZA==\r\n"
"\r\n";
CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createProxyRequest());
} }
void HttpRequestTest::testIsRangeSatisfied() void HttpRequestTest::testIsRangeSatisfied()
@ -621,6 +593,11 @@ void HttpRequestTest::testUserAgent()
CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createRequest()); CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createRequest());
SharedHandle<Request> proxyRequest(new Request());
CPPUNIT_ASSERT(proxyRequest->setUrl("http://localhost:9000"));
httpRequest.setProxyRequest(proxyRequest);
std::string expectedTextForProxy = "CONNECT localhost:8080 HTTP/1.1\r\n" std::string expectedTextForProxy = "CONNECT localhost:8080 HTTP/1.1\r\n"
"User-Agent: aria2 (Linux)\r\n" "User-Agent: aria2 (Linux)\r\n"
"Host: localhost:8080\r\n" "Host: localhost:8080\r\n"

View File

@ -328,51 +328,29 @@ void OptionHandlerTest::testFloatNumberOptionHandler_min_max()
void OptionHandlerTest::testHttpProxyOptionHandler() void OptionHandlerTest::testHttpProxyOptionHandler()
{ {
HttpProxyOptionHandler handler(PREF_HTTP_PROXY, HttpProxyOptionHandler handler(PREF_HTTP_PROXY, "", "");
"",
"",
PREF_HTTP_PROXY_HOST,
PREF_HTTP_PROXY_PORT);
CPPUNIT_ASSERT(handler.canHandle(PREF_HTTP_PROXY)); CPPUNIT_ASSERT(handler.canHandle(PREF_HTTP_PROXY));
CPPUNIT_ASSERT(!handler.canHandle("foobar")); CPPUNIT_ASSERT(!handler.canHandle("foobar"));
Option option; Option option;
handler.parse(&option, "bar:80"); handler.parse(&option, "proxy:65535");
CPPUNIT_ASSERT_EQUAL(std::string("bar:80"), option.get(PREF_HTTP_PROXY)); CPPUNIT_ASSERT_EQUAL(std::string("http://proxy:65535"),
CPPUNIT_ASSERT_EQUAL(std::string("bar"), option.get(PREF_HTTP_PROXY_HOST)); option.get(PREF_HTTP_PROXY));
CPPUNIT_ASSERT_EQUAL(std::string("80"), option.get(PREF_HTTP_PROXY_PORT));
CPPUNIT_ASSERT_EQUAL(std::string(V_TRUE), option.get(PREF_HTTP_PROXY_ENABLED)); handler.parse(&option, "http://proxy:8080");
CPPUNIT_ASSERT_EQUAL(std::string("http://proxy:8080"),
option.get(PREF_HTTP_PROXY));
handler.parse(&option, "ftp://proxy:8080");
CPPUNIT_ASSERT_EQUAL(std::string("http://ftp://proxy:8080"),
option.get(PREF_HTTP_PROXY));
try { try {
handler.parse(&option, "bar"); handler.parse(&option, "http://bar:65536");
CPPUNIT_FAIL("exception must be thrown."); CPPUNIT_FAIL("exception must be thrown.");
} catch(Exception& e) { } catch(Exception& e) {
std::cerr << e.stackTrace() << std::endl; std::cerr << e.stackTrace() << std::endl;
} }
try { CPPUNIT_ASSERT_EQUAL(std::string("[http://][USER:PASSWORD@]HOST[:PORT]"),
handler.parse(&option, "bar:");
CPPUNIT_FAIL("exception must be thrown.");
} catch(Exception& e) {
std::cerr << e.stackTrace() << std::endl;
}
try {
handler.parse(&option, ":");
CPPUNIT_FAIL("exception must be thrown.");
} catch(Exception& e) {
std::cerr << e.stackTrace() << std::endl;
}
try {
handler.parse(&option, ":80");
CPPUNIT_FAIL("exception must be thrown.");
} catch(Exception& e) {
std::cerr << e.stackTrace() << std::endl;
}
try {
handler.parse(&option, "foo:bar");
CPPUNIT_FAIL("exception must be thrown.");
} catch(Exception& e) {
std::cerr << e.stackTrace() << std::endl;
}
CPPUNIT_ASSERT_EQUAL(std::string("HOST:PORT"),
handler.createPossibleValuesString()); handler.createPossibleValuesString());
} }