2008-09-26 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

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
pull/1/head
Tatsuhiro Tsujikawa 2008-09-25 16:06:29 +00:00
parent 789e1926cb
commit 87a5bb50c2
5 changed files with 37 additions and 15 deletions

View File

@ -1,3 +1,13 @@
2008-09-26 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
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 <tujikawa at rednoah dot com>
Now colon is required for username and password in FTP URL, like:

View File

@ -46,6 +46,7 @@
#include "a2functional.h"
#include "TimeA2.h"
#include <numeric>
#include <cassert>
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> 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";

View File

@ -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<std::string, std::string> userPass =
Util::split(authPart, A2STR::COLON_C);
_username = Util::urldecode(userPass.first);
_password = Util::urldecode(userPass.second);
}
std::pair<std::string, std::string> userPass =
Util::split(authPart, A2STR::COLON_C);
_username = Util::urldecode(userPass.first);
_password = Util::urldecode(userPass.second);
hostPart.erase(0, atmarkp+1);
}
std::pair<std::string, std::string> hostAndPort;

View File

@ -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"

View File

@ -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());
}