diff --git a/ChangeLog b/ChangeLog index e51daaae..cfd6be5e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2008-09-26 Tatsuhiro Tsujikawa + + Reverted previous change. + Insert username+'@' to URI(after ftp://) when URI is FTP scheme and + username is not in URI. + * src/HttpRequest.cc + * src/Request.cc + * test/HttpRequestTest.cc + * test/RequestTest.cc + 2008-09-25 Tatsuhiro Tsujikawa Now colon is required for username and password in FTP URL, like: diff --git a/src/HttpRequest.cc b/src/HttpRequest.cc index 82d9c443..a5dd0e59 100644 --- a/src/HttpRequest.cc +++ b/src/HttpRequest.cc @@ -46,6 +46,7 @@ #include "a2functional.h" #include "TimeA2.h" #include +#include namespace aria2 { @@ -133,9 +134,21 @@ std::string HttpRequest::getHostText(const std::string& host, uint16_t port) con std::string HttpRequest::createRequest() const { + SharedHandle authConfig = AuthConfigFactorySingleton::instance() + ->createAuthConfig(request); + std::string requestLine = "GET "; if(getProtocol() == Request::PROTO_FTP || proxyEnabled) { - requestLine += getCurrentURI(); + if(getProtocol() == Request::PROTO_FTP && + request->getUsername().empty() && !authConfig->getUser().empty()) { + // Insert user into URI, like ftp://USER@host/ + std::string uri = getCurrentURI(); + assert(uri.size() >= 6); + uri.insert(6, Util::urlencode(authConfig->getUser())+"@"); + requestLine += uri; + } else { + requestLine += getCurrentURI(); + } } else { if(getDir() == A2STR::SLASH_C) { requestLine += getDir(); @@ -192,11 +205,9 @@ std::string HttpRequest::createRequest() const if(proxyEnabled && proxyAuthEnabled) { requestLine += getProxyAuthString(); } - std::string authString = AuthConfigFactorySingleton::instance() - ->createAuthConfig(request)->getAuthText(); - if(authString != ":") { + if(!authConfig->getUser().empty()) { requestLine += "Authorization: Basic "+ - Base64::encode(authString)+"\r\n"; + Base64::encode(authConfig->getAuthText())+"\r\n"; } if(getPreviousURI().size()) { requestLine += "Referer: "+getPreviousURI()+"\r\n"; diff --git a/src/Request.cc b/src/Request.cc index f3cba967..4daf4aaf 100644 --- a/src/Request.cc +++ b/src/Request.cc @@ -136,12 +136,10 @@ bool Request::parseUrl(const std::string& url) { std::string::size_type atmarkp = hostPart.find_last_of("@"); if(atmarkp != std::string::npos) { std::string authPart = hostPart.substr(0, atmarkp); - if(authPart.find(":") != std::string::npos) { - std::pair userPass = - Util::split(authPart, A2STR::COLON_C); - _username = Util::urldecode(userPass.first); - _password = Util::urldecode(userPass.second); - } + std::pair userPass = + Util::split(authPart, A2STR::COLON_C); + _username = Util::urldecode(userPass.first); + _password = Util::urldecode(userPass.second); hostPart.erase(0, atmarkp+1); } std::pair hostAndPort; diff --git a/test/HttpRequestTest.cc b/test/HttpRequestTest.cc index 41c58888..e4a8548b 100644 --- a/test/HttpRequestTest.cc +++ b/test/HttpRequestTest.cc @@ -349,7 +349,9 @@ void HttpRequestTest::testCreateRequest_ftp() httpRequest.configure(_option.get()); - std::string expectedText = "GET ftp://localhost:8080/archives/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n" + std::string expectedText = + "GET ftp://aria2user@localhost:8080/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" @@ -368,7 +370,9 @@ void HttpRequestTest::testCreateRequest_ftp() httpRequest.configure(_option.get()); - expectedText = "GET ftp://localhost:8080/archives/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n" + expectedText = + "GET ftp://aria2user@localhost:8080/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" diff --git a/test/RequestTest.cc b/test/RequestTest.cc index 24b597ef..807ec821 100644 --- a/test/RequestTest.cc +++ b/test/RequestTest.cc @@ -402,8 +402,7 @@ void RequestTest::testSetUrl_username() CPPUNIT_ASSERT_EQUAL(std::string("localhost"), req.getHost()); CPPUNIT_ASSERT_EQUAL(std::string("/download"), req.getDir()); CPPUNIT_ASSERT_EQUAL(std::string("aria2-1.0.0.tar.bz2"), req.getFile()); - // No ":" is foundin 'aria2user', so username and password is left blank. - CPPUNIT_ASSERT_EQUAL(std::string(""), req.getUsername()); + CPPUNIT_ASSERT_EQUAL(std::string("aria2user"), req.getUsername()); CPPUNIT_ASSERT_EQUAL(std::string(""), req.getPassword()); }