summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2008-09-25 14:37:28 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2008-09-25 14:37:28 +0000
commit92d702fa5349c722c6b59256bafe552c8b5cd8a1 (patch)
tree43dd76d729ceaf937351f15a428680f3a290f5a5 /src
parent6bc233f414b74bf3acf4abf5d5655c236e78ae41 (diff)
2008-09-25 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Use netrc for HTTP. Now FTP user/password is sent in Authorization header when --ftp-via-http-proxy=get is given. * src/AuthConfigFactory.cc * src/HttpRequest.cc * src/HttpRequest.h * src/NetrcAuthResolver.cc * src/NetrcAuthResolver.h * src/OptionHandlerFactory.cc * src/option_processing.cc * src/prefs.cc * src/prefs.h * test/AuthConfigFactoryTest.cc * test/HttpRequestTest.cc * test/NetrcAuthResolverTest.cc
Diffstat (limited to 'src')
-rw-r--r--src/AuthConfigFactory.cc3
-rw-r--r--src/HttpRequest.cc8
-rw-r--r--src/HttpRequest.h11
-rw-r--r--src/NetrcAuthResolver.cc19
-rw-r--r--src/NetrcAuthResolver.h10
-rw-r--r--src/OptionHandlerFactory.cc1
-rw-r--r--src/option_processing.cc3
-rw-r--r--src/prefs.cc2
-rw-r--r--src/prefs.h2
9 files changed, 36 insertions, 23 deletions
diff --git a/src/AuthConfigFactory.cc b/src/AuthConfigFactory.cc
index 9291e442..bbcdba1b 100644
--- a/src/AuthConfigFactory.cc
+++ b/src/AuthConfigFactory.cc
@@ -88,11 +88,12 @@ AuthConfigFactory::createAuthConfig(const std::string& user, const std::string&
AuthResolverHandle AuthConfigFactory::createHttpAuthResolver() const
{
AbstractAuthResolverHandle resolver;
- if(true || _option->getAsBool(PREF_NO_NETRC)) {
+ if(_option->getAsBool(PREF_NO_NETRC)) {
resolver.reset(new DefaultAuthResolver());
} else {
NetrcAuthResolverHandle authResolver(new NetrcAuthResolver());
authResolver->setNetrc(_netrc);
+ authResolver->ignoreDefault();
resolver = authResolver;
}
resolver->setUserDefinedAuthConfig(createAuthConfig(_option->get(PREF_HTTP_USER), _option->get(PREF_HTTP_PASSWD)));
diff --git a/src/HttpRequest.cc b/src/HttpRequest.cc
index 08235683..82d9c443 100644
--- a/src/HttpRequest.cc
+++ b/src/HttpRequest.cc
@@ -52,7 +52,6 @@ namespace aria2 {
const std::string HttpRequest::USER_AGENT("aria2");
HttpRequest::HttpRequest():entityLength(0),
- authEnabled(false),
proxyEnabled(false),
proxyAuthEnabled(false),
_contentEncodingEnabled(true),
@@ -193,9 +192,11 @@ std::string HttpRequest::createRequest() const
if(proxyEnabled && proxyAuthEnabled) {
requestLine += getProxyAuthString();
}
- if(authEnabled) {
+ std::string authString = AuthConfigFactorySingleton::instance()
+ ->createAuthConfig(request)->getAuthText();
+ if(authString != ":") {
requestLine += "Authorization: Basic "+
- Base64::encode(AuthConfigFactorySingleton::instance()->createAuthConfig(request)->getAuthText())+"\r\n";
+ Base64::encode(authString)+"\r\n";
}
if(getPreviousURI().size()) {
requestLine += "Referer: "+getPreviousURI()+"\r\n";
@@ -274,7 +275,6 @@ void HttpRequest::addAcceptType(const std::string& type)
void HttpRequest::configure(const Option* option)
{
- authEnabled = option->getAsBool(PREF_HTTP_AUTH_ENABLED);
proxyEnabled =
option->getAsBool(PREF_HTTP_PROXY_ENABLED) &&
option->get(PREF_HTTP_PROXY_METHOD) == V_GET;
diff --git a/src/HttpRequest.h b/src/HttpRequest.h
index c6f05b94..9f364873 100644
--- a/src/HttpRequest.h
+++ b/src/HttpRequest.h
@@ -59,8 +59,6 @@ private:
uint64_t entityLength;
- bool authEnabled;
-
bool proxyEnabled;
bool proxyAuthEnabled;
@@ -147,10 +145,8 @@ public:
/**
* Configures this object with option.
* Following values are evaluated:
- * PREF_HTTP_AUTH_ENABLED, PREF_HTTP_PROXY_ENABLED,
+ * PREF_HTTP_PROXY_ENABLED,
* PREF_HTTP_PROXY_METHOD, PREF_HTTP_PROXY_AUTH_ENABLED,
- * PREF_HTTP_USER, PREF_HTTP_PASSWD,
- * PREF_HTTP_PROXY_USER, PREF_HTTP_PROXY_PASSWD
* The evaluation results are stored in instance variables.
*/
void configure(const Option* option);
@@ -165,11 +161,6 @@ public:
this->proxyAuthEnabled = proxyAuthEnabled;
}
- void setAuthEnabled(bool authEnabled)
- {
- this->authEnabled = authEnabled;
- }
-
void enableContentEncoding();
void disableContentEncoding();
diff --git a/src/NetrcAuthResolver.cc b/src/NetrcAuthResolver.cc
index 647af81a..6a77d16d 100644
--- a/src/NetrcAuthResolver.cc
+++ b/src/NetrcAuthResolver.cc
@@ -38,6 +38,8 @@
namespace aria2 {
+NetrcAuthResolver::NetrcAuthResolver():_ignoreDefault(false) {}
+
AuthConfigHandle NetrcAuthResolver::resolveAuthConfig(const std::string& hostname)
{
if(_userDefinedAuthConfig.isNull()) {
@@ -56,7 +58,12 @@ AuthConfigHandle NetrcAuthResolver::findNetrcAuthenticator(const std::string& ho
if(auth.isNull()) {
return _defaultAuthConfig;
} else {
- return SharedHandle<AuthConfig>(new AuthConfig(auth->getLogin(), auth->getPassword()));
+ if(_ignoreDefault && auth->getMachine() == "") {
+ return _defaultAuthConfig;
+ } else {
+ return SharedHandle<AuthConfig>
+ (new AuthConfig(auth->getLogin(), auth->getPassword()));
+ }
}
}
}
@@ -71,4 +78,14 @@ NetrcHandle NetrcAuthResolver::getNetrc() const
return _netrc;
}
+void NetrcAuthResolver::ignoreDefault()
+{
+ _ignoreDefault = true;
+}
+
+void NetrcAuthResolver::useDefault()
+{
+ _ignoreDefault = false;
+}
+
} // namespace aria2
diff --git a/src/NetrcAuthResolver.h b/src/NetrcAuthResolver.h
index bf19559f..290dcbe7 100644
--- a/src/NetrcAuthResolver.h
+++ b/src/NetrcAuthResolver.h
@@ -45,8 +45,12 @@ class NetrcAuthResolver : public AbstractAuthResolver {
private:
SharedHandle<Netrc> _netrc;
+ bool _ignoreDefault;
+
SharedHandle<AuthConfig> findNetrcAuthenticator(const std::string& hostname) const;
public:
+ NetrcAuthResolver();
+
virtual ~NetrcAuthResolver() {}
virtual SharedHandle<AuthConfig> resolveAuthConfig(const std::string& hostname);
@@ -54,6 +58,12 @@ public:
void setNetrc(const SharedHandle<Netrc>& netrc);
SharedHandle<Netrc> getNetrc() const;
+
+ // Ignores default token of netrc
+ void ignoreDefault();
+
+ // Uses default token of netrc
+ void useDefault();
};
typedef SharedHandle<NetrcAuthResolver> NetrcAuthResolverHandle;
diff --git a/src/OptionHandlerFactory.cc b/src/OptionHandlerFactory.cc
index bd9825d1..ae39e29a 100644
--- a/src/OptionHandlerFactory.cc
+++ b/src/OptionHandlerFactory.cc
@@ -612,6 +612,7 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers()
TEXT_NO_NETRC,
V_FALSE)); // TODO ommit?
op->addTag(TAG_FTP);
+ op->addTag(TAG_HTTP);
handlers.push_back(op);
}
// BitTorrent/Metalink Options
diff --git a/src/option_processing.cc b/src/option_processing.cc
index 7045fd7b..50c4bf5a 100644
--- a/src/option_processing.cc
+++ b/src/option_processing.cc
@@ -524,9 +524,6 @@ Option* option_processing(int argc, char* const argv[])
exit(EXIT_FAILURE);
}
}
- if(op->defined(PREF_HTTP_USER)) {
- op->put(PREF_HTTP_AUTH_ENABLED, V_TRUE);
- }
if(op->defined(PREF_HTTP_PROXY_USER)) {
op->put(PREF_HTTP_PROXY_AUTH_ENABLED, V_TRUE);
}
diff --git a/src/prefs.cc b/src/prefs.cc
index 27d9c2be..e55b7332 100644
--- a/src/prefs.cc
+++ b/src/prefs.cc
@@ -172,8 +172,6 @@ const std::string PREF_HTTP_PASSWD("http-passwd");
// values: basic
const std::string PREF_HTTP_AUTH_SCHEME("http-auth-scheme");
const std::string V_BASIC("basic");
-// values: true | false
-const std::string PREF_HTTP_AUTH_ENABLED("http-auth-enabled");
// values: string
const std::string PREF_USER_AGENT("user-agent");
// value: string that your file system recognizes as a file name.
diff --git a/src/prefs.h b/src/prefs.h
index af4bee9f..75822be6 100644
--- a/src/prefs.h
+++ b/src/prefs.h
@@ -176,8 +176,6 @@ extern const std::string PREF_HTTP_PASSWD;
// values: basic
extern const std::string PREF_HTTP_AUTH_SCHEME;
extern const std::string V_BASIC;
-// values: true | false
-extern const std::string PREF_HTTP_AUTH_ENABLED;
// values: string
extern const std::string PREF_USER_AGENT;
// value: string that your file system recognizes as a file name.