2010-03-07 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

url -> uri in Request class.
	* src/AbstractCommand.cc
	* src/AdaptiveURISelector.cc
	* src/DefaultBtAnnounce.cc
	* src/FeedbackURISelector.cc
	* src/FileEntry.cc
	* src/FileEntry.h
	* src/HttpRequest.h
	* src/HttpResponse.cc
	* src/InitiateConnectionCommandFactory.cc
	* src/Metalink2RequestGroup.cc
	* src/OptionHandlerImpl.h
	* src/ProtocolDetector.cc
	* src/Request.cc
	* src/Request.h
	* src/XmlRpcMethodImpl.cc
	* test/AuthConfigFactoryTest.cc
	* test/FtpConnectionTest.cc
	* test/HttpRequestTest.cc
	* test/HttpResponseTest.cc
	* test/RequestTest.cc
pull/1/head
Tatsuhiro Tsujikawa 2010-03-07 10:36:42 +00:00
parent 6ce44b001d
commit b0f180c99c
21 changed files with 372 additions and 348 deletions

View File

@ -1,3 +1,27 @@
2010-03-07 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
url -> uri in Request class.
* src/AbstractCommand.cc
* src/AdaptiveURISelector.cc
* src/DefaultBtAnnounce.cc
* src/FeedbackURISelector.cc
* src/FileEntry.cc
* src/FileEntry.h
* src/HttpRequest.h
* src/HttpResponse.cc
* src/InitiateConnectionCommandFactory.cc
* src/Metalink2RequestGroup.cc
* src/OptionHandlerImpl.h
* src/ProtocolDetector.cc
* src/Request.cc
* src/Request.h
* src/XmlRpcMethodImpl.cc
* test/AuthConfigFactoryTest.cc
* test/FtpConnectionTest.cc
* test/HttpRequestTest.cc
* test/HttpResponseTest.cc
* test/RequestTest.cc
2010-03-07 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net> 2010-03-07 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Added getServers XML-RPC method. Added getServers XML-RPC method.

View File

@ -111,7 +111,7 @@ bool AbstractCommand::execute() {
if(logger->debug()) { if(logger->debug()) {
logger->debug logger->debug
("CUID#%d - Discard original URI=%s because it is requested.", ("CUID#%d - Discard original URI=%s because it is requested.",
cuid, req->getUrl().c_str()); cuid, req->getUri().c_str());
} }
return prepareForRetry(0); return prepareForRetry(0);
} }
@ -208,10 +208,10 @@ bool AbstractCommand::execute() {
} else { } else {
logger->error(MSG_DOWNLOAD_ABORTED, logger->error(MSG_DOWNLOAD_ABORTED,
DL_ABORT_EX2(StringFormat DL_ABORT_EX2(StringFormat
("URI=%s", req->getCurrentUrl().c_str()).str(),err), ("URI=%s", req->getCurrentUri().c_str()).str(),err),
cuid, req->getUrl().c_str()); cuid, req->getUri().c_str());
_fileEntry->addURIResult(req->getUrl(), err.getCode()); _fileEntry->addURIResult(req->getUri(), err.getCode());
_requestGroup->setLastUriResult(req->getUrl(), err.getCode()); _requestGroup->setLastUriResult(req->getUri(), err.getCode());
} }
onAbort(); onAbort();
tryReserved(); tryReserved();
@ -220,8 +220,8 @@ bool AbstractCommand::execute() {
assert(!req.isNull()); assert(!req.isNull());
logger->info(MSG_RESTARTING_DOWNLOAD, logger->info(MSG_RESTARTING_DOWNLOAD,
DL_RETRY_EX2(StringFormat DL_RETRY_EX2(StringFormat
("URI=%s", req->getCurrentUrl().c_str()).str(),err), ("URI=%s", req->getCurrentUri().c_str()).str(),err),
cuid, req->getUrl().c_str()); cuid, req->getUri().c_str());
req->addTryCount(); req->addTryCount();
req->resetRedirectCount(); req->resetRedirectCount();
const unsigned int maxTries = getOption()->getAsInt(PREF_MAX_TRIES); const unsigned int maxTries = getOption()->getAsInt(PREF_MAX_TRIES);
@ -229,9 +229,9 @@ bool AbstractCommand::execute() {
if(isAbort) { if(isAbort) {
onAbort(); onAbort();
logger->info(MSG_MAX_TRY, cuid, req->getTryCount()); logger->info(MSG_MAX_TRY, cuid, req->getTryCount());
logger->error(MSG_DOWNLOAD_ABORTED, err, cuid, req->getUrl().c_str()); logger->error(MSG_DOWNLOAD_ABORTED, err, cuid, req->getUri().c_str());
_fileEntry->addURIResult(req->getUrl(), err.getCode()); _fileEntry->addURIResult(req->getUri(), err.getCode());
_requestGroup->setLastUriResult(req->getUrl(), err.getCode()); _requestGroup->setLastUriResult(req->getUri(), err.getCode());
tryReserved(); tryReserved();
return true; return true;
} else { } else {
@ -240,8 +240,8 @@ bool AbstractCommand::execute() {
} catch(DownloadFailureException& err) { } catch(DownloadFailureException& err) {
logger->error(EX_EXCEPTION_CAUGHT, err); logger->error(EX_EXCEPTION_CAUGHT, err);
if(!req.isNull()) { if(!req.isNull()) {
_fileEntry->addURIResult(req->getUrl(), err.getCode()); _fileEntry->addURIResult(req->getUri(), err.getCode());
_requestGroup->setLastUriResult(req->getUrl(), err.getCode()); _requestGroup->setLastUriResult(req->getUri(), err.getCode());
} }
_requestGroup->setHaltRequested(true); _requestGroup->setHaltRequested(true);
return true; return true;
@ -281,7 +281,7 @@ bool AbstractCommand::prepareForRetry(time_t wait) {
_fileEntry->poolRequest(req); _fileEntry->poolRequest(req);
if(logger->debug()) { if(logger->debug()) {
logger->debug("CUID#%d - Pooling request URI=%s", logger->debug("CUID#%d - Pooling request URI=%s",
cuid, req->getUrl().c_str()); cuid, req->getUri().c_str());
} }
if(!_requestGroup->getSegmentMan().isNull()) { if(!_requestGroup->getSegmentMan().isNull()) {
_requestGroup->getSegmentMan()->recognizeSegmentFor(_fileEntry); _requestGroup->getSegmentMan()->recognizeSegmentFor(_fileEntry);
@ -305,7 +305,7 @@ void AbstractCommand::onAbort() {
// TODO This might be a problem if the failure is caused by proxy. // TODO This might be a problem if the failure is caused by proxy.
e->_requestGroupMan->getOrCreateServerStat(req->getHost(), e->_requestGroupMan->getOrCreateServerStat(req->getHost(),
req->getProtocol())->setError(); req->getProtocol())->setError();
_fileEntry->removeIdenticalURI(req->getUrl()); _fileEntry->removeIdenticalURI(req->getUri());
_fileEntry->removeRequest(req); _fileEntry->removeRequest(req);
} }
if(logger->debug()) { if(logger->debug()) {
@ -421,7 +421,7 @@ static bool isProxyRequest
(const std::string& protocol, const SharedHandle<Option>& option) (const std::string& protocol, const SharedHandle<Option>& option)
{ {
const std::string& proxyUri = getProxyUri(protocol, option); const std::string& proxyUri = getProxyUri(protocol, option);
return !proxyUri.empty() && Request().setUrl(proxyUri); return !proxyUri.empty() && Request().setUri(proxyUri);
} }
class DomainMatch { class DomainMatch {
@ -468,7 +468,7 @@ SharedHandle<Request> AbstractCommand::createProxyRequest() const
std::string proxy = getProxyUri(req->getProtocol(), getOption()); std::string proxy = getProxyUri(req->getProtocol(), getOption());
if(!proxy.empty()) { if(!proxy.empty()) {
proxyRequest.reset(new Request()); proxyRequest.reset(new Request());
if(proxyRequest->setUrl(proxy)) { if(proxyRequest->setUri(proxy)) {
if(logger->debug()) { if(logger->debug()) {
logger->debug("CUID#%d - Using proxy", cuid); logger->debug("CUID#%d - Using proxy", cuid);
} }

View File

@ -341,7 +341,7 @@ SharedHandle<ServerStat> AdaptiveURISelector::getServerStats
(const std::string& uri) const (const std::string& uri) const
{ {
Request r; Request r;
r.setUrl(uri); r.setUri(uri);
return _serverStatMan->find(r.getHost(), r.getProtocol()); return _serverStatMan->find(r.getHost(), r.getProtocol());
} }

View File

@ -108,7 +108,7 @@ bool DefaultBtAnnounce::isAnnounceReady() {
static bool uriHasQuery(const std::string& uri) static bool uriHasQuery(const std::string& uri)
{ {
Request req; Request req;
req.setUrl(uri); req.setUri(uri);
return !req.getQuery().empty(); return !req.getQuery().empty();
} }
@ -141,50 +141,50 @@ std::string DefaultBtAnnounce::getAnnounceUrl() {
TransferStat stat = peerStorage->calculateStat(); TransferStat stat = peerStorage->calculateStat();
uint64_t left = uint64_t left =
pieceStorage->getTotalLength()-pieceStorage->getCompletedLength(); pieceStorage->getTotalLength()-pieceStorage->getCompletedLength();
std::string url = announceList.getAnnounce(); std::string uri = announceList.getAnnounce();
url += uriHasQuery(url) ? "&" : "?"; uri += uriHasQuery(uri) ? "&" : "?";
url += "info_hash="; uri += "info_hash=";
url += util::torrentUrlencode(bittorrent::getInfoHash(_downloadContext), uri += util::torrentUrlencode(bittorrent::getInfoHash(_downloadContext),
INFO_HASH_LENGTH); INFO_HASH_LENGTH);
url += "&peer_id="; uri += "&peer_id=";
url += util::torrentUrlencode(bittorrent::getStaticPeerId(), PEER_ID_LENGTH); uri += util::torrentUrlencode(bittorrent::getStaticPeerId(), PEER_ID_LENGTH);
url += "&uploaded="; uri += "&uploaded=";
url += util::uitos(stat.getSessionUploadLength()); uri += util::uitos(stat.getSessionUploadLength());
url += "&downloaded="; uri += "&downloaded=";
url += util::uitos(stat.getSessionDownloadLength()); uri += util::uitos(stat.getSessionDownloadLength());
url += "&left="; uri += "&left=";
url += util::uitos(left); uri += util::uitos(left);
url += "&compact=1"; uri += "&compact=1";
url += "&key="; uri += "&key=";
// Use last 8 bytes of peer ID as a key // Use last 8 bytes of peer ID as a key
size_t keyLen = 8; size_t keyLen = 8;
url += util::torrentUrlencode uri += util::torrentUrlencode
(bittorrent::getStaticPeerId()+PEER_ID_LENGTH-keyLen, keyLen); (bittorrent::getStaticPeerId()+PEER_ID_LENGTH-keyLen, keyLen);
url += "&numwant="; uri += "&numwant=";
url += util::uitos(numWant); uri += util::uitos(numWant);
url += "&no_peer_id=1"; uri += "&no_peer_id=1";
if(btRuntime->getListenPort() > 0) { if(btRuntime->getListenPort() > 0) {
url += "&port="; uri += "&port=";
url += util::uitos(btRuntime->getListenPort()); uri += util::uitos(btRuntime->getListenPort());
} }
std::string event = announceList.getEventString(); std::string event = announceList.getEventString();
if(!event.empty()) { if(!event.empty()) {
url += "&event="; uri += "&event=";
url += event; uri += event;
} }
if(!trackerId.empty()) { if(!trackerId.empty()) {
url += "&trackerid="+util::torrentUrlencode(trackerId); uri += "&trackerid="+util::torrentUrlencode(trackerId);
} }
if(option->getAsBool(PREF_BT_REQUIRE_CRYPTO)) { if(option->getAsBool(PREF_BT_REQUIRE_CRYPTO)) {
url += "&requirecrypto=1"; uri += "&requirecrypto=1";
} else { } else {
url += "&supportcrypto=1"; uri += "&supportcrypto=1";
} }
if(!option->blank(PREF_BT_EXTERNAL_IP)) { if(!option->blank(PREF_BT_EXTERNAL_IP)) {
url += "&ip="; uri += "&ip=";
url += option->get(PREF_BT_EXTERNAL_IP); uri += option->get(PREF_BT_EXTERNAL_IP);
} }
return url; return uri;
} }
void DefaultBtAnnounce::announceStart() { void DefaultBtAnnounce::announceStart() {

View File

@ -76,7 +76,7 @@ std::string FeedbackURISelector::select(FileEntry* fileEntry)
for(std::deque<std::string>::iterator i = uris.begin(), eoi = urisLast; for(std::deque<std::string>::iterator i = uris.begin(), eoi = urisLast;
i != eoi; ++i) { i != eoi; ++i) {
Request r; Request r;
r.setUrl(*i); r.setUri(*i);
SharedHandle<ServerStat> ss = _serverStatMan->find(r.getHost(), SharedHandle<ServerStat> ss = _serverStatMan->find(r.getHost(),
r.getProtocol()); r.getProtocol());
if(!ss.isNull() && ss->isOK() && ss->getDownloadSpeed() > SPEED_THRESHOLD) { if(!ss.isNull() && ss->isOK() && ss->getDownloadSpeed() > SPEED_THRESHOLD) {
@ -87,7 +87,7 @@ std::string FeedbackURISelector::select(FileEntry* fileEntry)
for(std::deque<std::string>::iterator i = uris.begin(), eoi = uris.end(); for(std::deque<std::string>::iterator i = uris.begin(), eoi = uris.end();
i != eoi; ++i) { i != eoi; ++i) {
Request r; Request r;
r.setUrl(*i); r.setUri(*i);
SharedHandle<ServerStat> ss = _serverStatMan->find(r.getHost(), SharedHandle<ServerStat> ss = _serverStatMan->find(r.getHost(),
r.getProtocol()); r.getProtocol());
// Skip ERROR state URI // Skip ERROR state URI

View File

@ -132,7 +132,7 @@ FileEntry::getRequest
return req; return req;
} }
req.reset(new Request()); req.reset(new Request());
if(req->setUrl(uri)) { if(req->setUri(uri)) {
if(!_singleHostMultiConnection) { if(!_singleHostMultiConnection) {
if(inFlightHost(_inFlightRequests.begin(), _inFlightRequests.end(), if(inFlightHost(_inFlightRequests.begin(), _inFlightRequests.end(),
req->getHost())) { req->getHost())) {
@ -243,7 +243,7 @@ void FileEntry::removeURIWhoseHostnameIs(const std::string& hostname)
for(std::deque<std::string>::const_iterator itr = _uris.begin(), for(std::deque<std::string>::const_iterator itr = _uris.begin(),
eoi = _uris.end(); itr != eoi; ++itr) { eoi = _uris.end(); itr != eoi; ++itr) {
if(((*itr).find(hostname) == std::string::npos) || if(((*itr).find(hostname) == std::string::npos) ||
(req.setUrl(*itr) && (req.getHost() != hostname))) { (req.setUri(*itr) && (req.getHost() != hostname))) {
newURIs.push_back(*itr); newURIs.push_back(*itr);
} }
} }
@ -337,7 +337,7 @@ static InputIterator findRequestByUri
(InputIterator first, InputIterator last, const T& uri) (InputIterator first, InputIterator last, const T& uri)
{ {
for(; first != last; ++first) { for(; first != last; ++first) {
if(!(*first)->removalRequested() && (*first)->getUrl() == uri) { if(!(*first)->removalRequested() && (*first)->getUri() == uri) {
return first; return first;
} }
} }

View File

@ -149,7 +149,7 @@ public:
bool addUri(const std::string& uri) bool addUri(const std::string& uri)
{ {
if(Request().setUrl(uri)) { if(Request().setUri(uri)) {
_uris.push_back(uri); _uris.push_back(uri);
return true; return true;
} else { } else {
@ -159,7 +159,7 @@ public:
bool insertUri(const std::string& uri, size_t pos) bool insertUri(const std::string& uri, size_t pos)
{ {
if(Request().setUrl(uri)) { if(Request().setUri(uri)) {
pos = std::min(pos, _uris.size()); pos = std::min(pos, _uris.size());
_uris.insert(_uris.begin()+pos, uri); _uris.insert(_uris.begin()+pos, uri);
return true; return true;

View File

@ -126,7 +126,7 @@ public:
const std::string& getCurrentURI() const const std::string& getCurrentURI() const
{ {
return request->getCurrentUrl(); return request->getCurrentUri();
} }
const std::string& getDir() const const std::string& getDir() const
@ -146,7 +146,7 @@ public:
const std::string& getPreviousURI() const const std::string& getPreviousURI() const
{ {
return request->getPreviousUrl(); return request->getPreviousUri();
} }
std::string getURIHost() const std::string getURIHost() const
@ -217,7 +217,7 @@ public:
(const SharedHandle<AuthConfigFactory>& factory, const Option* option); (const SharedHandle<AuthConfigFactory>& factory, const Option* option);
/* /*
* To use proxy, pass proxy string to Request::setUrl() and set it this * To use proxy, pass proxy string to Request::setUri() and set it this
* object. * object.
*/ */
void setProxyRequest(const SharedHandle<Request>& proxyRequest); void setProxyRequest(const SharedHandle<Request>& proxyRequest);

View File

@ -132,14 +132,14 @@ bool HttpResponse::isRedirect() const
void HttpResponse::processRedirect() void HttpResponse::processRedirect()
{ {
if(httpRequest->getRequest()->redirectUrl(getRedirectURI())) { if(httpRequest->getRequest()->redirectUri(getRedirectURI())) {
logger->info(MSG_REDIRECT, cuid, logger->info(MSG_REDIRECT, cuid,
httpRequest->getRequest()->getCurrentUrl().c_str()); httpRequest->getRequest()->getCurrentUri().c_str());
} else { } else {
throw DL_RETRY_EX throw DL_RETRY_EX
(StringFormat("CUID#%d - Redirect to %s failed. It may not be a valid" (StringFormat("CUID#%d - Redirect to %s failed. It may not be a valid"
" URI.", cuid, " URI.", cuid,
httpRequest->getRequest()->getCurrentUrl().c_str()).str()); httpRequest->getRequest()->getCurrentUri().c_str()).str());
} }
} }

View File

@ -74,8 +74,8 @@ InitiateConnectionCommandFactory::createInitiateConnectionCommand
} else if(req->getProtocol() == Request::PROTO_FTP) { } else if(req->getProtocol() == Request::PROTO_FTP) {
if(req->getFile().empty()) { if(req->getFile().empty()) {
throw DL_ABORT_EX throw DL_ABORT_EX
(StringFormat("FTP URL %s doesn't contain file path.", (StringFormat("FTP URI %s doesn't contain file path.",
req->getUrl().c_str()).str()); req->getUri().c_str()).str());
} }
return return
new FtpInitiateConnectionCommand(cuid, req, fileEntry, requestGroup, e); new FtpInitiateConnectionCommand(cuid, req, fileEntry, requestGroup, e);

View File

@ -69,19 +69,19 @@ namespace aria2 {
Metalink2RequestGroup::Metalink2RequestGroup(): Metalink2RequestGroup::Metalink2RequestGroup():
_logger(LogFactory::getInstance()) {} _logger(LogFactory::getInstance()) {}
class AccumulateNonP2PUrl { class AccumulateNonP2PUri {
private: private:
std::vector<std::string>& urlsPtr; std::vector<std::string>& urisPtr;
public: public:
AccumulateNonP2PUrl(std::vector<std::string>& urlsPtr) AccumulateNonP2PUri(std::vector<std::string>& urisPtr)
:urlsPtr(urlsPtr) {} :urisPtr(urisPtr) {}
void operator()(const SharedHandle<MetalinkResource>& resource) { void operator()(const SharedHandle<MetalinkResource>& resource) {
switch(resource->type) { switch(resource->type) {
case MetalinkResource::TYPE_HTTP: case MetalinkResource::TYPE_HTTP:
case MetalinkResource::TYPE_HTTPS: case MetalinkResource::TYPE_HTTPS:
case MetalinkResource::TYPE_FTP: case MetalinkResource::TYPE_FTP:
urlsPtr.push_back(resource->url); urisPtr.push_back(resource->url);
break; break;
default: default:
break; break;
@ -89,9 +89,9 @@ public:
} }
}; };
class FindBitTorrentUrl { class FindBitTorrentUri {
public: public:
FindBitTorrentUrl() {} FindBitTorrentUri() {}
bool operator()(const SharedHandle<MetalinkResource>& resource) { bool operator()(const SharedHandle<MetalinkResource>& resource) {
if(resource->type == MetalinkResource::TYPE_BITTORRENT) { if(resource->type == MetalinkResource::TYPE_BITTORRENT) {
@ -232,7 +232,7 @@ Metalink2RequestGroup::createRequestGroup
entry->reorderResourcesByPriority(); entry->reorderResourcesByPriority();
std::vector<std::string> uris; std::vector<std::string> uris;
std::for_each(entry->resources.begin(), entry->resources.end(), std::for_each(entry->resources.begin(), entry->resources.end(),
AccumulateNonP2PUrl(uris)); AccumulateNonP2PUri(uris));
// If piece hash is specified in the metalink, // If piece hash is specified in the metalink,
// make segment size equal to piece hash size. // make segment size equal to piece hash size.
size_t pieceLength; size_t pieceLength;
@ -286,7 +286,7 @@ Metalink2RequestGroup::createRequestGroup
(*i)->reorderResourcesByPriority(); (*i)->reorderResourcesByPriority();
std::vector<std::string> uris; std::vector<std::string> uris;
std::for_each((*i)->resources.begin(), (*i)->resources.end(), std::for_each((*i)->resources.begin(), (*i)->resources.end(),
AccumulateNonP2PUrl(uris)); AccumulateNonP2PUri(uris));
SharedHandle<FileEntry> fe SharedHandle<FileEntry> fe
(new FileEntry (new FileEntry
(util::applyDir(option->get(PREF_DIR), (util::applyDir(option->get(PREF_DIR),

View File

@ -562,14 +562,14 @@ public:
option.put(_optName, optarg); option.put(_optName, optarg);
} else { } else {
Request req; Request req;
std::string url; std::string uri;
if(util::startsWith(optarg, "http://")) { if(util::startsWith(optarg, "http://")) {
url = optarg; uri = optarg;
} else { } else {
url = "http://"+optarg; uri = "http://"+optarg;
} }
if(req.setUrl(url)) { if(req.setUri(uri)) {
option.put(_optName, url); option.put(_optName, uri);
} else { } else {
throw DL_ABORT_EX(_("unrecognized proxy format")); throw DL_ABORT_EX(_("unrecognized proxy format"));
} }

View File

@ -53,7 +53,7 @@ ProtocolDetector::~ProtocolDetector() {}
bool ProtocolDetector::isStreamProtocol(const std::string& uri) const bool ProtocolDetector::isStreamProtocol(const std::string& uri) const
{ {
return Request().setUrl(uri); return Request().setUri(uri);
} }
bool ProtocolDetector::guessTorrentFile(const std::string& uri) const bool ProtocolDetector::guessTorrentFile(const std::string& uri) const

View File

@ -67,13 +67,13 @@ Request::Request():
_removalRequested(false) _removalRequested(false)
{} {}
static std::string removeFragment(const std::string& url) static std::string removeFragment(const std::string& uri)
{ {
std::string::size_type sharpIndex = url.find("#"); std::string::size_type sharpIndex = uri.find("#");
if(sharpIndex == std::string::npos) { if(sharpIndex == std::string::npos) {
return url; return uri;
} else { } else {
return url.substr(0, sharpIndex); return uri.substr(0, sharpIndex);
} }
} }
@ -83,7 +83,7 @@ static bool isHexNumber(const char c)
('a' <= c && c <= 'f'); ('a' <= c && c <= 'f');
} }
static std::string urlencode(const std::string& src) static std::string percentEncode(const std::string& src)
{ {
std::string result = src; std::string result = src;
if(src.empty()) { if(src.empty()) {
@ -92,7 +92,7 @@ static std::string urlencode(const std::string& src)
result += " "; result += " ";
for(int index = src.size()-1; index >= 0; --index) { for(int index = src.size()-1; index >= 0; --index) {
const unsigned char c = result[index]; const unsigned char c = result[index];
// '/' is not urlencoded because src is expected to be a path. // '/' is not percent encoded because src is expected to be a path.
if(!util::inRFC3986ReservedChars(c) && !util::inRFC3986UnreservedChars(c)) { if(!util::inRFC3986ReservedChars(c) && !util::inRFC3986UnreservedChars(c)) {
if(c == '%') { if(c == '%') {
if(!isHexNumber(result[index+1]) || !isHexNumber(result[index+2])) { if(!isHexNumber(result[index+1]) || !isHexNumber(result[index+2])) {
@ -107,47 +107,47 @@ static std::string urlencode(const std::string& src)
return result; return result;
} }
bool Request::setUrl(const std::string& url) { bool Request::setUri(const std::string& uri) {
_supportsPersistentConnection = true; _supportsPersistentConnection = true;
_url = url; _uri = uri;
return parseUrl(_url); return parseUri(_uri);
} }
bool Request::resetUrl() { bool Request::resetUri() {
_previousUrl = _referer; _previousUri = _referer;
_supportsPersistentConnection = true; _supportsPersistentConnection = true;
return parseUrl(_url); return parseUri(_uri);
} }
void Request::setReferer(const std::string& url) void Request::setReferer(const std::string& uri)
{ {
_referer = _previousUrl = urlencode(removeFragment(url)); _referer = _previousUri = percentEncode(removeFragment(uri));
} }
bool Request::redirectUrl(const std::string& url) { bool Request::redirectUri(const std::string& uri) {
_previousUrl = A2STR::NIL; _previousUri = A2STR::NIL;
_supportsPersistentConnection = true; _supportsPersistentConnection = true;
++_redirectCount; ++_redirectCount;
std::string redirectedUrl; std::string redirectedUri;
if(url.find("://") == std::string::npos) { if(uri.find("://") == std::string::npos) {
// rfc2616 requires absolute URI should be provided by Location header // rfc2616 requires absolute URI should be provided by Location header
// field, but some servers don't obey this rule. // field, but some servers don't obey this rule.
if(util::startsWith(url, "/")) { if(util::startsWith(uri, "/")) {
// abosulute path // abosulute path
redirectedUrl = strconcat(_protocol, "://", _host, url); redirectedUri = strconcat(_protocol, "://", _host, uri);
} else { } else {
// relative path // relative path
redirectedUrl = strconcat(_protocol, "://", _host, _dir, "/", url); redirectedUri = strconcat(_protocol, "://", _host, _dir, "/", uri);
} }
} else { } else {
redirectedUrl = url; redirectedUri = uri;
} }
return parseUrl(redirectedUrl); return parseUri(redirectedUri);
} }
bool Request::parseUrl(const std::string& srcUrl) { bool Request::parseUri(const std::string& srcUri) {
const std::string url = urlencode(removeFragment(srcUrl)); const std::string uri = percentEncode(removeFragment(srcUri));
_currentUrl = url; _currentUri = uri;
_host = A2STR::NIL; _host = A2STR::NIL;
_port = 0; _port = 0;
_dir = A2STR::NIL; _dir = A2STR::NIL;
@ -173,21 +173,21 @@ bool Request::parseUrl(const std::string& srcUrl) {
// queryFirst // queryFirst
// find query part // find query part
std::string::const_iterator queryFirst = url.begin(); std::string::const_iterator queryFirst = uri.begin();
for(; queryFirst != url.end(); ++queryFirst) { for(; queryFirst != uri.end(); ++queryFirst) {
if(*queryFirst == '?') break; if(*queryFirst == '?') break;
} }
_query = std::string(queryFirst, url.end()); _query = std::string(queryFirst, uri.end());
// find protocol // find protocol
std::string::size_type protocolOffset = url.find("://"); std::string::size_type protocolOffset = uri.find("://");
if(protocolOffset == std::string::npos) return false; if(protocolOffset == std::string::npos) return false;
_protocol = std::string(url.begin(), url.begin()+protocolOffset); _protocol = std::string(uri.begin(), uri.begin()+protocolOffset);
uint16_t defPort; uint16_t defPort;
if((defPort = FeatureConfig::getInstance()->getDefaultPort(_protocol)) == 0) { if((defPort = FeatureConfig::getInstance()->getDefaultPort(_protocol)) == 0) {
return false; return false;
} }
// find authority // find authority
std::string::const_iterator authorityFirst = url.begin()+protocolOffset+3; std::string::const_iterator authorityFirst = uri.begin()+protocolOffset+3;
std::string::const_iterator authorityLast = authorityFirst; std::string::const_iterator authorityLast = authorityFirst;
for(; authorityLast != queryFirst; ++authorityLast) { for(; authorityLast != queryFirst; ++authorityLast) {
if(*authorityLast == '/') break; if(*authorityLast == '/') break;
@ -318,7 +318,7 @@ const SharedHandle<PeerStat>& Request::initPeerStat()
// Use host and protocol in original URI, because URI selector // Use host and protocol in original URI, because URI selector
// selects URI based on original URI, not redirected one. // selects URI based on original URI, not redirected one.
Request origReq; Request origReq;
origReq.setUrl(_url); origReq.setUri(_uri);
_peerStat.reset(new PeerStat(0, origReq.getHost(), origReq.getProtocol())); _peerStat.reset(new PeerStat(0, origReq.getHost(), origReq.getProtocol()));
return _peerStat; return _peerStat;
} }

View File

@ -46,14 +46,14 @@ namespace aria2 {
class Request { class Request {
private: private:
std::string _url; std::string _uri;
std::string _currentUrl; std::string _currentUri;
/** /**
* URL previously requested to the server. This is used as Referer * URI previously requested to the server. This is used as Referer
*/ */
std::string _previousUrl; std::string _previousUri;
/** /**
* URL used as Referer in the initial request * URI used as Referer in the initial request
*/ */
std::string _referer; std::string _referer;
std::string _protocol; std::string _protocol;
@ -90,17 +90,17 @@ private:
bool _removalRequested; bool _removalRequested;
bool parseUrl(const std::string& url); bool parseUri(const std::string& uri);
public: public:
Request(); Request();
// Sets url to _url and parses URL. Returns true if parsing goes // Sets uri to _uri and parses URI. Returns true if parsing goes
// successful, otherwise returns false. // successful, otherwise returns false.
bool setUrl(const std::string& url); bool setUri(const std::string& uri);
// Parses URL. _url field are not altered by this method. Returns // Parses URI. _uri field are not altered by this method. Returns
// true if parsing goes successful, otherwise returns false. // true if parsing goes successful, otherwise returns false.
bool redirectUrl(const std::string& url); bool redirectUri(const std::string& uri);
bool resetUrl(); bool resetUri();
void resetTryCount() { _tryCount = 0; } void resetTryCount() { _tryCount = 0; }
void addTryCount() { ++_tryCount; } void addTryCount() { ++_tryCount; }
unsigned int getTryCount() const { return _tryCount; } unsigned int getTryCount() const { return _tryCount; }
@ -112,12 +112,12 @@ public:
return _redirectCount; return _redirectCount;
} }
// Returns URI passed by setUrl() // Returns URI passed by setUri()
const std::string& getUrl() const { return _url; } const std::string& getUri() const { return _uri; }
const std::string& getCurrentUrl() const { return _currentUrl; } const std::string& getCurrentUri() const { return _currentUri; }
const std::string& getPreviousUrl() const { return _previousUrl; } const std::string& getPreviousUri() const { return _previousUri; }
const std::string& getReferer() const { return _referer; } const std::string& getReferer() const { return _referer; }
void setReferer(const std::string& url); void setReferer(const std::string& uri);
const std::string& getProtocol() const { return _protocol; } const std::string& getProtocol() const { return _protocol; }
const std::string& getHost() const { return _host; } const std::string& getHost() const { return _host; }
// Same as getHost(), but for IPv6 literal addresses, enclose them // Same as getHost(), but for IPv6 literal addresses, enclose them

View File

@ -912,8 +912,8 @@ BDE GetServersXmlRpcMethod::process
SharedHandle<PeerStat> ps = (*ri)->getPeerStat(); SharedHandle<PeerStat> ps = (*ri)->getPeerStat();
if(!ps.isNull()) { if(!ps.isNull()) {
BDE serverEntry = BDE::dict(); BDE serverEntry = BDE::dict();
serverEntry[KEY_URI] = (*ri)->getUrl(); serverEntry[KEY_URI] = (*ri)->getUri();
serverEntry[KEY_CURRENT_URI] = (*ri)->getCurrentUrl(); serverEntry[KEY_CURRENT_URI] = (*ri)->getCurrentUri();
serverEntry[KEY_DOWNLOAD_SPEED] = serverEntry[KEY_DOWNLOAD_SPEED] =
util::uitos(ps->calculateDownloadSpeed()); util::uitos(ps->calculateDownloadSpeed());
servers << serverEntry; servers << serverEntry;

View File

@ -32,7 +32,7 @@ CPPUNIT_TEST_SUITE_REGISTRATION( AuthConfigFactoryTest );
void AuthConfigFactoryTest::testCreateAuthConfig_http() void AuthConfigFactoryTest::testCreateAuthConfig_http()
{ {
SharedHandle<Request> req(new Request()); SharedHandle<Request> req(new Request());
req->setUrl("http://localhost/download/aria2-1.0.0.tar.bz2"); req->setUri("http://localhost/download/aria2-1.0.0.tar.bz2");
Option option; Option option;
option.put(PREF_NO_NETRC, V_FALSE); option.put(PREF_NO_NETRC, V_FALSE);
@ -63,7 +63,7 @@ void AuthConfigFactoryTest::testCreateAuthConfig_http()
factory.createAuthConfig(req, &option)->getAuthText()); factory.createAuthConfig(req, &option)->getAuthText());
// See default token in netrc is ignored. // See default token in netrc is ignored.
req->setUrl("http://mirror/"); req->setUri("http://mirror/");
CPPUNIT_ASSERT(!factory.activateBasicCred("mirror", "/", &option)); CPPUNIT_ASSERT(!factory.activateBasicCred("mirror", "/", &option));
@ -81,7 +81,7 @@ void AuthConfigFactoryTest::testCreateAuthConfig_http()
factory.createAuthConfig(req, &option)->getAuthText()); factory.createAuthConfig(req, &option)->getAuthText());
// username and password in URI // username and password in URI
req->setUrl("http://aria2user:aria2password@localhost/download/aria2-1.0.0.tar.bz2"); req->setUri("http://aria2user:aria2password@localhost/download/aria2-1.0.0.tar.bz2");
CPPUNIT_ASSERT_EQUAL(std::string("aria2user:aria2password"), CPPUNIT_ASSERT_EQUAL(std::string("aria2user:aria2password"),
factory.createAuthConfig(req, &option)->getAuthText()); factory.createAuthConfig(req, &option)->getAuthText());
} }
@ -89,7 +89,7 @@ void AuthConfigFactoryTest::testCreateAuthConfig_http()
void AuthConfigFactoryTest::testCreateAuthConfig_httpNoChallenge() void AuthConfigFactoryTest::testCreateAuthConfig_httpNoChallenge()
{ {
SharedHandle<Request> req(new Request()); SharedHandle<Request> req(new Request());
req->setUrl("http://localhost/download/aria2-1.0.0.tar.bz2"); req->setUri("http://localhost/download/aria2-1.0.0.tar.bz2");
Option option; Option option;
option.put(PREF_NO_NETRC, V_FALSE); option.put(PREF_NO_NETRC, V_FALSE);
@ -115,7 +115,7 @@ void AuthConfigFactoryTest::testCreateAuthConfig_httpNoChallenge()
factory.createAuthConfig(req, &option)->getAuthText()); factory.createAuthConfig(req, &option)->getAuthText());
// See default token in netrc is ignored. // See default token in netrc is ignored.
req->setUrl("http://mirror/"); req->setUri("http://mirror/");
CPPUNIT_ASSERT(factory.createAuthConfig(req, &option).isNull()); CPPUNIT_ASSERT(factory.createAuthConfig(req, &option).isNull());
@ -127,7 +127,7 @@ void AuthConfigFactoryTest::testCreateAuthConfig_httpNoChallenge()
factory.createAuthConfig(req, &option)->getAuthText()); factory.createAuthConfig(req, &option)->getAuthText());
// username and password in URI // username and password in URI
req->setUrl("http://aria2user:aria2password@localhost/download/aria2-1.0.0.tar.bz2"); req->setUri("http://aria2user:aria2password@localhost/download/aria2-1.0.0.tar.bz2");
CPPUNIT_ASSERT_EQUAL(std::string("aria2user:aria2password"), CPPUNIT_ASSERT_EQUAL(std::string("aria2user:aria2password"),
factory.createAuthConfig(req, &option)->getAuthText()); factory.createAuthConfig(req, &option)->getAuthText());
} }
@ -135,7 +135,7 @@ void AuthConfigFactoryTest::testCreateAuthConfig_httpNoChallenge()
void AuthConfigFactoryTest::testCreateAuthConfig_ftp() void AuthConfigFactoryTest::testCreateAuthConfig_ftp()
{ {
SharedHandle<Request> req(new Request()); SharedHandle<Request> req(new Request());
req->setUrl("ftp://localhost/download/aria2-1.0.0.tar.bz2"); req->setUri("ftp://localhost/download/aria2-1.0.0.tar.bz2");
Option option; Option option;
option.put(PREF_NO_NETRC, V_FALSE); option.put(PREF_NO_NETRC, V_FALSE);
@ -167,13 +167,13 @@ void AuthConfigFactoryTest::testCreateAuthConfig_ftp()
factory.createAuthConfig(req, &option)->getAuthText()); factory.createAuthConfig(req, &option)->getAuthText());
// username and password in URI // username and password in URI
req->setUrl("ftp://aria2user:aria2password@localhost/download/aria2-1.0.0.tar.bz2"); req->setUri("ftp://aria2user:aria2password@localhost/download/aria2-1.0.0.tar.bz2");
CPPUNIT_ASSERT_EQUAL(std::string("aria2user:aria2password"), CPPUNIT_ASSERT_EQUAL(std::string("aria2user:aria2password"),
factory.createAuthConfig(req, &option)->getAuthText()); factory.createAuthConfig(req, &option)->getAuthText());
// username in URI, but no password. We have DefaultAuthenticator // username in URI, but no password. We have DefaultAuthenticator
// but username is not aria2user // but username is not aria2user
req->setUrl("ftp://aria2user@localhost/download/aria2-1.0.0.tar.bz2"); req->setUri("ftp://aria2user@localhost/download/aria2-1.0.0.tar.bz2");
CPPUNIT_ASSERT_EQUAL(std::string("aria2user:userDefinedPassword"), CPPUNIT_ASSERT_EQUAL(std::string("aria2user:userDefinedPassword"),
factory.createAuthConfig(req, &option)->getAuthText()); factory.createAuthConfig(req, &option)->getAuthText());
@ -190,7 +190,7 @@ void AuthConfigFactoryTest::testCreateAuthConfig_ftp()
CPPUNIT_ASSERT_EQUAL(std::string("aria2user:netrcpass"), CPPUNIT_ASSERT_EQUAL(std::string("aria2user:netrcpass"),
factory.createAuthConfig(req, &option)->getAuthText()); factory.createAuthConfig(req, &option)->getAuthText());
// No netrc entry for host mirror, so "userDefinedPassword" is used. // No netrc entry for host mirror, so "userDefinedPassword" is used.
req->setUrl("ftp://aria2user@mirror/download/aria2-1.0.0.tar.bz2"); req->setUri("ftp://aria2user@mirror/download/aria2-1.0.0.tar.bz2");
CPPUNIT_ASSERT_EQUAL(std::string("aria2user:userDefinedPassword"), CPPUNIT_ASSERT_EQUAL(std::string("aria2user:userDefinedPassword"),
factory.createAuthConfig(req, &option)->getAuthText()); factory.createAuthConfig(req, &option)->getAuthText());
} }
@ -213,27 +213,27 @@ void AuthConfigFactoryTest::testUpdateBasicCred()
(AuthConfigFactory::BasicCred("jack", "jackx","mirror", "/doc", true)); (AuthConfigFactory::BasicCred("jack", "jackx","mirror", "/doc", true));
SharedHandle<Request> req(new Request()); SharedHandle<Request> req(new Request());
req->setUrl("http://localhost/download/v2.6/Changelog"); req->setUri("http://localhost/download/v2.6/Changelog");
CPPUNIT_ASSERT_EQUAL(std::string("price:j38jdc"), CPPUNIT_ASSERT_EQUAL(std::string("price:j38jdc"),
factory.createAuthConfig(req, &option)->getAuthText()); factory.createAuthConfig(req, &option)->getAuthText());
req->setUrl("http://localhost/documents/reference.html"); req->setUri("http://localhost/documents/reference.html");
CPPUNIT_ASSERT_EQUAL(std::string("alice:ium8"), CPPUNIT_ASSERT_EQUAL(std::string("alice:ium8"),
factory.createAuthConfig(req, &option)->getAuthText()); factory.createAuthConfig(req, &option)->getAuthText());
req->setUrl("http://localhost/documents2/manual.html"); req->setUri("http://localhost/documents2/manual.html");
CPPUNIT_ASSERT_EQUAL(std::string("myname:mypass"), CPPUNIT_ASSERT_EQUAL(std::string("myname:mypass"),
factory.createAuthConfig(req, &option)->getAuthText()); factory.createAuthConfig(req, &option)->getAuthText());
req->setUrl("http://localhost/doc/readme.txt"); req->setUri("http://localhost/doc/readme.txt");
CPPUNIT_ASSERT_EQUAL(std::string("myname:mypass"), CPPUNIT_ASSERT_EQUAL(std::string("myname:mypass"),
factory.createAuthConfig(req, &option)->getAuthText()); factory.createAuthConfig(req, &option)->getAuthText());
req->setUrl("http://local/"); req->setUri("http://local/");
CPPUNIT_ASSERT(factory.createAuthConfig(req, &option).isNull()); CPPUNIT_ASSERT(factory.createAuthConfig(req, &option).isNull());
req->setUrl("http://mirror/"); req->setUri("http://mirror/");
CPPUNIT_ASSERT(factory.createAuthConfig(req, &option).isNull()); CPPUNIT_ASSERT(factory.createAuthConfig(req, &option).isNull());
} }

View File

@ -54,7 +54,7 @@ public:
_listenPort = addrinfo.second; _listenPort = addrinfo.second;
SharedHandle<Request> req(new Request()); SharedHandle<Request> req(new Request());
req->setUrl("ftp://localhost/dir/file.img"); req->setUri("ftp://localhost/dir/file.img");
_clientSocket.reset(new SocketCore()); _clientSocket.reset(new SocketCore());
_clientSocket->establishConnection("localhost", _listenPort); _clientSocket->establishConnection("localhost", _listenPort);

View File

@ -126,7 +126,7 @@ void HttpRequestTest::testCreateRequest()
SharedHandle<Request> request(new Request()); SharedHandle<Request> request(new Request());
request->supportsPersistentConnection(true); request->supportsPersistentConnection(true);
request->setUrl("http://localhost:8080/archives/aria2-1.0.0.tar.bz2"); request->setUri("http://localhost:8080/archives/aria2-1.0.0.tar.bz2");
p.reset(new Piece(0, 1024)); p.reset(new Piece(0, 1024));
SharedHandle<Segment> segment(new PiecedSegment(1024, p)); SharedHandle<Segment> segment(new PiecedSegment(1024, p));
@ -196,7 +196,7 @@ void HttpRequestTest::testCreateRequest()
CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createRequest()); CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createRequest());
// redirection set persistent connection flag to true // redirection set persistent connection flag to true
request->redirectUrl("http://localhost:8080/archives/download/aria2-1.0.0.tar.bz2"); request->redirectUri("http://localhost:8080/archives/download/aria2-1.0.0.tar.bz2");
expectedText = "GET /archives/download/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n" expectedText = "GET /archives/download/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n"
"User-Agent: aria2\r\n" "User-Agent: aria2\r\n"
@ -228,7 +228,7 @@ void HttpRequestTest::testCreateRequest()
request->setKeepAliveHint(false); request->setKeepAliveHint(false);
request->resetUrl(); request->resetUri();
p.reset(new Piece(0, 1024*1024)); p.reset(new Piece(0, 1024*1024));
segment.reset(new PiecedSegment(1024*1024, p)); segment.reset(new PiecedSegment(1024*1024, p));
@ -255,7 +255,7 @@ void HttpRequestTest::testCreateRequest()
// enable http proxy auth // enable http proxy auth
SharedHandle<Request> proxyRequest(new Request()); SharedHandle<Request> proxyRequest(new Request());
CPPUNIT_ASSERT(proxyRequest->setUrl CPPUNIT_ASSERT(proxyRequest->setUri
("http://aria2proxyuser:aria2proxypasswd@localhost:9000")); ("http://aria2proxyuser:aria2proxypasswd@localhost:9000"));
httpRequest.setProxyRequest(proxyRequest); httpRequest.setProxyRequest(proxyRequest);
@ -292,7 +292,7 @@ void HttpRequestTest::testCreateRequest()
request->setPipeliningHint(false); request->setPipeliningHint(false);
// turn off proxy auth // turn off proxy auth
CPPUNIT_ASSERT(proxyRequest->setUrl("http://localhost:9000")); CPPUNIT_ASSERT(proxyRequest->setUri("http://localhost:9000"));
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"
@ -314,10 +314,10 @@ void HttpRequestTest::testCreateRequest_ftp()
_option->put(PREF_FTP_PASSWD, "aria2passwd"); _option->put(PREF_FTP_PASSWD, "aria2passwd");
SharedHandle<Request> request(new Request()); SharedHandle<Request> request(new Request());
request->setUrl("ftp://localhost:8080/archives/aria2-1.0.0.tar.bz2"); request->setUri("ftp://localhost:8080/archives/aria2-1.0.0.tar.bz2");
SharedHandle<Request> proxyRequest(new Request()); SharedHandle<Request> proxyRequest(new Request());
CPPUNIT_ASSERT(proxyRequest->setUrl CPPUNIT_ASSERT(proxyRequest->setUri
("http://localhost:9000")); ("http://localhost:9000"));
HttpRequest httpRequest; HttpRequest httpRequest;
@ -349,7 +349,7 @@ void HttpRequestTest::testCreateRequest_ftp()
CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createRequest()); CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createRequest());
// test proxy authorization // test proxy authorization
CPPUNIT_ASSERT(proxyRequest->setUrl CPPUNIT_ASSERT(proxyRequest->setUri
("http://aria2proxyuser:aria2proxypasswd@localhost:9000")); ("http://aria2proxyuser:aria2proxypasswd@localhost:9000"));
expectedText = expectedText =
@ -372,7 +372,7 @@ void HttpRequestTest::testCreateRequest_ftp()
void HttpRequestTest::testCreateRequest_with_cookie() void HttpRequestTest::testCreateRequest_with_cookie()
{ {
SharedHandle<Request> request(new Request()); SharedHandle<Request> request(new Request());
request->setUrl("http://localhost/archives/aria2-1.0.0.tar.bz2"); request->setUri("http://localhost/archives/aria2-1.0.0.tar.bz2");
SharedHandle<Piece> p(new Piece(0, 1024*1024)); SharedHandle<Piece> p(new Piece(0, 1024*1024));
SharedHandle<Segment> segment SharedHandle<Segment> segment
(new PiecedSegment(1024*1024, p)); (new PiecedSegment(1024*1024, p));
@ -410,7 +410,7 @@ void HttpRequestTest::testCreateRequest_with_cookie()
CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createRequest()); CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createRequest());
request->setUrl("http://localhost/archives/download/aria2-1.0.0.tar.bz2"); request->setUri("http://localhost/archives/download/aria2-1.0.0.tar.bz2");
expectedText = "GET /archives/download/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n" expectedText = "GET /archives/download/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n"
"User-Agent: aria2\r\n" "User-Agent: aria2\r\n"
@ -424,7 +424,7 @@ void HttpRequestTest::testCreateRequest_with_cookie()
CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createRequest()); CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createRequest());
request->setUrl("http://www.aria2.org/archives/download/aria2-1.0.0.tar.bz2"); request->setUri("http://www.aria2.org/archives/download/aria2-1.0.0.tar.bz2");
expectedText = "GET /archives/download/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n" expectedText = "GET /archives/download/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n"
"User-Agent: aria2\r\n" "User-Agent: aria2\r\n"
@ -438,7 +438,7 @@ void HttpRequestTest::testCreateRequest_with_cookie()
CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createRequest()); CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createRequest());
request->setUrl("https://www.aria2.org/archives/download/" request->setUri("https://www.aria2.org/archives/download/"
"aria2-1.0.0.tar.bz2"); "aria2-1.0.0.tar.bz2");
expectedText = "GET /archives/download/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n" expectedText = "GET /archives/download/aria2-1.0.0.tar.bz2 HTTP/1.1\r\n"
@ -458,7 +458,7 @@ void HttpRequestTest::testCreateRequest_with_cookie()
void HttpRequestTest::testCreateRequest_query() void HttpRequestTest::testCreateRequest_query()
{ {
SharedHandle<Request> request(new Request()); SharedHandle<Request> request(new Request());
request->setUrl("http://localhost/wiki?id=9ad5109a-b8a5-4edf-9373-56a1c34ae138"); request->setUri("http://localhost/wiki?id=9ad5109a-b8a5-4edf-9373-56a1c34ae138");
HttpRequest httpRequest; HttpRequest httpRequest;
httpRequest.disableContentEncoding(); httpRequest.disableContentEncoding();
httpRequest.setRequest(request); httpRequest.setRequest(request);
@ -481,7 +481,7 @@ void HttpRequestTest::testCreateRequest_head()
{ {
SharedHandle<Request> request(new Request()); SharedHandle<Request> request(new Request());
request->setMethod(Request::METHOD_HEAD); request->setMethod(Request::METHOD_HEAD);
request->setUrl("http://localhost/aria2-1.0.0.tar.bz2"); request->setUri("http://localhost/aria2-1.0.0.tar.bz2");
HttpRequest httpRequest; HttpRequest httpRequest;
httpRequest.setRequest(request); httpRequest.setRequest(request);
@ -497,12 +497,12 @@ void HttpRequestTest::testCreateRequest_head()
void HttpRequestTest::testCreateProxyRequest() void HttpRequestTest::testCreateProxyRequest()
{ {
SharedHandle<Request> request(new Request()); SharedHandle<Request> request(new Request());
request->setUrl("http://localhost/archives/aria2-1.0.0.tar.bz2"); request->setUri("http://localhost/archives/aria2-1.0.0.tar.bz2");
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()); SharedHandle<Request> proxyRequest(new Request());
CPPUNIT_ASSERT(proxyRequest->setUrl("http://localhost:9000")); CPPUNIT_ASSERT(proxyRequest->setUri("http://localhost:9000"));
HttpRequest httpRequest; HttpRequest httpRequest;
@ -544,7 +544,7 @@ void HttpRequestTest::testCreateProxyRequest()
CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createProxyRequest()); CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createProxyRequest());
// test proxy authorization // test proxy authorization
CPPUNIT_ASSERT(proxyRequest->setUrl CPPUNIT_ASSERT(proxyRequest->setUri
("http://aria2proxyuser:aria2proxypasswd@localhost:9000")); ("http://aria2proxyuser:aria2proxypasswd@localhost:9000"));
expectedText = "CONNECT localhost:80 HTTP/1.1\r\n" expectedText = "CONNECT localhost:80 HTTP/1.1\r\n"
@ -561,7 +561,7 @@ void HttpRequestTest::testIsRangeSatisfied()
{ {
SharedHandle<Request> request(new Request()); SharedHandle<Request> request(new Request());
request->supportsPersistentConnection(true); request->supportsPersistentConnection(true);
request->setUrl("http://localhost:8080/archives/aria2-1.0.0.tar.bz2"); request->setUri("http://localhost:8080/archives/aria2-1.0.0.tar.bz2");
request->setPipeliningHint(false); // default: false request->setPipeliningHint(false); // default: false
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));
@ -616,7 +616,7 @@ void HttpRequestTest::testIsRangeSatisfied()
void HttpRequestTest::testUserAgent() void HttpRequestTest::testUserAgent()
{ {
SharedHandle<Request> request(new Request()); SharedHandle<Request> request(new Request());
request->setUrl("http://localhost:8080/archives/aria2-1.0.0.tar.bz2"); request->setUri("http://localhost:8080/archives/aria2-1.0.0.tar.bz2");
//SharedHandle<Piece> p(new Piece(0, 1024)); //SharedHandle<Piece> p(new Piece(0, 1024));
//SharedHandle<Segment> segment(new PiecedSegment(1024, p)); //SharedHandle<Segment> segment(new PiecedSegment(1024, p));
@ -640,7 +640,7 @@ void HttpRequestTest::testUserAgent()
CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createRequest()); CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createRequest());
SharedHandle<Request> proxyRequest(new Request()); SharedHandle<Request> proxyRequest(new Request());
CPPUNIT_ASSERT(proxyRequest->setUrl("http://localhost:9000")); CPPUNIT_ASSERT(proxyRequest->setUri("http://localhost:9000"));
httpRequest.setProxyRequest(proxyRequest); httpRequest.setProxyRequest(proxyRequest);
@ -656,7 +656,7 @@ void HttpRequestTest::testUserAgent()
void HttpRequestTest::testAddHeader() void HttpRequestTest::testAddHeader()
{ {
SharedHandle<Request> request(new Request()); SharedHandle<Request> request(new Request());
request->setUrl("http://localhost/archives/aria2-1.0.0.tar.bz2"); request->setUri("http://localhost/archives/aria2-1.0.0.tar.bz2");
HttpRequest httpRequest; HttpRequest httpRequest;
httpRequest.disableContentEncoding(); httpRequest.disableContentEncoding();
@ -684,7 +684,7 @@ void HttpRequestTest::testAddAcceptType()
"muffin/chocolate" }; "muffin/chocolate" };
SharedHandle<Request> request(new Request()); SharedHandle<Request> request(new Request());
request->setUrl("http://localhost/archives/aria2-1.0.0.tar.bz2"); request->setUri("http://localhost/archives/aria2-1.0.0.tar.bz2");
HttpRequest httpRequest; HttpRequest httpRequest;
httpRequest.disableContentEncoding(); httpRequest.disableContentEncoding();
@ -709,7 +709,7 @@ void HttpRequestTest::testAddAcceptType()
void HttpRequestTest::testEnableAcceptEncoding() void HttpRequestTest::testEnableAcceptEncoding()
{ {
SharedHandle<Request> request(new Request()); SharedHandle<Request> request(new Request());
request->setUrl("http://localhost/archives/aria2-1.0.0.tar.bz2"); request->setUri("http://localhost/archives/aria2-1.0.0.tar.bz2");
HttpRequest httpRequest; HttpRequest httpRequest;
httpRequest.setRequest(request); httpRequest.setRequest(request);
@ -740,7 +740,7 @@ void HttpRequestTest::testEnableAcceptEncoding()
void HttpRequestTest::testCreateRequest_ipv6LiteralAddr() void HttpRequestTest::testCreateRequest_ipv6LiteralAddr()
{ {
SharedHandle<Request> request(new Request()); SharedHandle<Request> request(new Request());
request->setUrl("http://[::1]/path"); request->setUri("http://[::1]/path");
HttpRequest httpRequest; HttpRequest httpRequest;
httpRequest.disableContentEncoding(); httpRequest.disableContentEncoding();
httpRequest.setRequest(request); httpRequest.setRequest(request);
@ -749,7 +749,7 @@ void HttpRequestTest::testCreateRequest_ipv6LiteralAddr()
CPPUNIT_ASSERT(httpRequest.createRequest().find("Host: [::1]") != std::string::npos); CPPUNIT_ASSERT(httpRequest.createRequest().find("Host: [::1]") != std::string::npos);
SharedHandle<Request> proxy(new Request()); SharedHandle<Request> proxy(new Request());
proxy->setUrl("http://proxy"); proxy->setUri("http://proxy");
httpRequest.setProxyRequest(proxy); httpRequest.setProxyRequest(proxy);
std::string proxyRequest = httpRequest.createProxyRequest(); std::string proxyRequest = httpRequest.createProxyRequest();
CPPUNIT_ASSERT(proxyRequest.find("Host: [::1]:80") != std::string::npos); CPPUNIT_ASSERT(proxyRequest.find("Host: [::1]:80") != std::string::npos);

View File

@ -137,7 +137,7 @@ void HttpResponseTest::testDeterminFilename_without_ContentDisposition()
SharedHandle<HttpHeader> httpHeader(new HttpHeader()); SharedHandle<HttpHeader> httpHeader(new HttpHeader());
SharedHandle<HttpRequest> httpRequest(new HttpRequest()); SharedHandle<HttpRequest> httpRequest(new HttpRequest());
SharedHandle<Request> request(new Request()); SharedHandle<Request> request(new Request());
request->setUrl("http://localhost/archives/aria2-1.0.0.tar.bz2"); request->setUri("http://localhost/archives/aria2-1.0.0.tar.bz2");
httpRequest->setRequest(request); httpRequest->setRequest(request);
httpResponse.setHttpHeader(httpHeader); httpResponse.setHttpHeader(httpHeader);
@ -155,7 +155,7 @@ void HttpResponseTest::testDeterminFilename_with_ContentDisposition_zero_length
httpHeader->put("Content-Disposition", "attachment; filename=\"\""); httpHeader->put("Content-Disposition", "attachment; filename=\"\"");
SharedHandle<HttpRequest> httpRequest(new HttpRequest()); SharedHandle<HttpRequest> httpRequest(new HttpRequest());
SharedHandle<Request> request(new Request()); SharedHandle<Request> request(new Request());
request->setUrl("http://localhost/archives/aria2-1.0.0.tar.bz2"); request->setUri("http://localhost/archives/aria2-1.0.0.tar.bz2");
httpRequest->setRequest(request); httpRequest->setRequest(request);
httpResponse.setHttpHeader(httpHeader); httpResponse.setHttpHeader(httpHeader);
@ -173,7 +173,7 @@ void HttpResponseTest::testDeterminFilename_with_ContentDisposition()
"attachment; filename=\"aria2-current.tar.bz2\""); "attachment; filename=\"aria2-current.tar.bz2\"");
SharedHandle<HttpRequest> httpRequest(new HttpRequest()); SharedHandle<HttpRequest> httpRequest(new HttpRequest());
SharedHandle<Request> request(new Request()); SharedHandle<Request> request(new Request());
request->setUrl("http://localhost/archives/aria2-1.0.0.tar.bz2"); request->setUri("http://localhost/archives/aria2-1.0.0.tar.bz2");
httpRequest->setRequest(request); httpRequest->setRequest(request);
httpResponse.setHttpHeader(httpHeader); httpResponse.setHttpHeader(httpHeader);
@ -362,7 +362,7 @@ void HttpResponseTest::testValidateResponse_good_range()
SharedHandle<FileEntry> fileEntry(new FileEntry("file", 1024*1024*10, 0)); SharedHandle<FileEntry> fileEntry(new FileEntry("file", 1024*1024*10, 0));
httpRequest->setFileEntry(fileEntry); httpRequest->setFileEntry(fileEntry);
SharedHandle<Request> request(new Request()); SharedHandle<Request> request(new Request());
request->setUrl("http://localhost/archives/aria2-1.0.0.tar.bz2"); request->setUri("http://localhost/archives/aria2-1.0.0.tar.bz2");
httpRequest->setRequest(request); httpRequest->setRequest(request);
httpResponse.setHttpRequest(httpRequest); httpResponse.setHttpRequest(httpRequest);
httpHeader->setResponseStatus("206"); httpHeader->setResponseStatus("206");
@ -389,7 +389,7 @@ void HttpResponseTest::testValidateResponse_bad_range()
SharedHandle<FileEntry> fileEntry(new FileEntry("file", 1024*1024*10, 0)); SharedHandle<FileEntry> fileEntry(new FileEntry("file", 1024*1024*10, 0));
httpRequest->setFileEntry(fileEntry); httpRequest->setFileEntry(fileEntry);
SharedHandle<Request> request(new Request()); SharedHandle<Request> request(new Request());
request->setUrl("http://localhost/archives/aria2-1.0.0.tar.bz2"); request->setUri("http://localhost/archives/aria2-1.0.0.tar.bz2");
httpRequest->setRequest(request); httpRequest->setRequest(request);
httpResponse.setHttpRequest(httpRequest); httpResponse.setHttpRequest(httpRequest);
httpHeader->setResponseStatus("206"); httpHeader->setResponseStatus("206");
@ -415,7 +415,7 @@ void HttpResponseTest::testValidateResponse_chunked()
SharedHandle<FileEntry> fileEntry(new FileEntry("file", 1024*1024*10, 0)); SharedHandle<FileEntry> fileEntry(new FileEntry("file", 1024*1024*10, 0));
httpRequest->setFileEntry(fileEntry); httpRequest->setFileEntry(fileEntry);
SharedHandle<Request> request(new Request()); SharedHandle<Request> request(new Request());
request->setUrl("http://localhost/archives/aria2-1.0.0.tar.bz2"); request->setUri("http://localhost/archives/aria2-1.0.0.tar.bz2");
httpRequest->setRequest(request); httpRequest->setRequest(request);
httpResponse.setHttpRequest(httpRequest); httpResponse.setHttpRequest(httpRequest);
httpHeader->setResponseStatus("206"); httpHeader->setResponseStatus("206");
@ -450,7 +450,7 @@ void HttpResponseTest::testProcessRedirect()
SharedHandle<HttpRequest> httpRequest(new HttpRequest()); SharedHandle<HttpRequest> httpRequest(new HttpRequest());
SharedHandle<Request> request(new Request()); SharedHandle<Request> request(new Request());
request->setUrl("http://localhost/archives/aria2-1.0.0.tar.bz2"); request->setUri("http://localhost/archives/aria2-1.0.0.tar.bz2");
httpRequest->setRequest(request); httpRequest->setRequest(request);
httpResponse.setHttpRequest(httpRequest); httpResponse.setHttpRequest(httpRequest);
@ -479,7 +479,7 @@ void HttpResponseTest::testRetrieveCookie()
SharedHandle<HttpRequest> httpRequest(new HttpRequest()); SharedHandle<HttpRequest> httpRequest(new HttpRequest());
SharedHandle<Request> request(new Request()); SharedHandle<Request> request(new Request());
request->setUrl("http://www.aria2.org/archives/aria2-1.0.0.tar.bz2"); request->setUri("http://www.aria2.org/archives/aria2-1.0.0.tar.bz2");
httpRequest->setRequest(request); httpRequest->setRequest(request);
SharedHandle<CookieStorage> st(new CookieStorage()); SharedHandle<CookieStorage> st(new CookieStorage());
httpRequest->setCookieStorage(st); httpRequest->setCookieStorage(st);

View File

@ -11,72 +11,72 @@ namespace aria2 {
class RequestTest:public CppUnit::TestFixture { class RequestTest:public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(RequestTest); CPPUNIT_TEST_SUITE(RequestTest);
CPPUNIT_TEST(testSetUrl1); CPPUNIT_TEST(testSetUri1);
CPPUNIT_TEST(testSetUrl2); CPPUNIT_TEST(testSetUri2);
CPPUNIT_TEST(testSetUrl3); CPPUNIT_TEST(testSetUri3);
CPPUNIT_TEST(testSetUrl4); CPPUNIT_TEST(testSetUri4);
CPPUNIT_TEST(testSetUrl5); CPPUNIT_TEST(testSetUri5);
CPPUNIT_TEST(testSetUrl6); CPPUNIT_TEST(testSetUri6);
CPPUNIT_TEST(testSetUrl7); CPPUNIT_TEST(testSetUri7);
CPPUNIT_TEST(testSetUrl8); CPPUNIT_TEST(testSetUri8);
CPPUNIT_TEST(testSetUrl9); CPPUNIT_TEST(testSetUri9);
CPPUNIT_TEST(testSetUrl10); CPPUNIT_TEST(testSetUri10);
CPPUNIT_TEST(testSetUrl11); CPPUNIT_TEST(testSetUri11);
CPPUNIT_TEST(testSetUrl12); CPPUNIT_TEST(testSetUri12);
CPPUNIT_TEST(testSetUrl13); CPPUNIT_TEST(testSetUri13);
CPPUNIT_TEST(testSetUrl14); CPPUNIT_TEST(testSetUri14);
CPPUNIT_TEST(testSetUrl15); CPPUNIT_TEST(testSetUri15);
CPPUNIT_TEST(testSetUrl16); CPPUNIT_TEST(testSetUri16);
CPPUNIT_TEST(testSetUrl17); CPPUNIT_TEST(testSetUri17);
CPPUNIT_TEST(testSetUrl18); CPPUNIT_TEST(testSetUri18);
CPPUNIT_TEST(testSetUrl19); CPPUNIT_TEST(testSetUri19);
CPPUNIT_TEST(testSetUrl20); CPPUNIT_TEST(testSetUri20);
CPPUNIT_TEST(testSetUrl_username); CPPUNIT_TEST(testSetUri_username);
CPPUNIT_TEST(testSetUrl_usernamePassword); CPPUNIT_TEST(testSetUri_usernamePassword);
CPPUNIT_TEST(testSetUrl_zeroUsername); CPPUNIT_TEST(testSetUri_zeroUsername);
CPPUNIT_TEST(testSetUrl_supportsPersistentConnection); CPPUNIT_TEST(testSetUri_supportsPersistentConnection);
CPPUNIT_TEST(testSetUrl_ipv6); CPPUNIT_TEST(testSetUri_ipv6);
CPPUNIT_TEST(testRedirectUrl); CPPUNIT_TEST(testRedirectUri);
CPPUNIT_TEST(testRedirectUrl2); CPPUNIT_TEST(testRedirectUri2);
CPPUNIT_TEST(testRedirectUrl_supportsPersistentConnection); CPPUNIT_TEST(testRedirectUri_supportsPersistentConnection);
CPPUNIT_TEST(testResetUrl); CPPUNIT_TEST(testResetUri);
CPPUNIT_TEST(testResetUrl_supportsPersistentConnection); CPPUNIT_TEST(testResetUri_supportsPersistentConnection);
CPPUNIT_TEST(testInnerLink); CPPUNIT_TEST(testInnerLink);
CPPUNIT_TEST(testInnerLinkInReferer); CPPUNIT_TEST(testInnerLinkInReferer);
CPPUNIT_TEST(testGetURIHost); CPPUNIT_TEST(testGetURIHost);
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
public: public:
void testSetUrl1(); void testSetUri1();
void testSetUrl2(); void testSetUri2();
void testSetUrl3(); void testSetUri3();
void testSetUrl4(); void testSetUri4();
void testSetUrl5(); void testSetUri5();
void testSetUrl6(); void testSetUri6();
void testSetUrl7(); void testSetUri7();
void testSetUrl8(); void testSetUri8();
void testSetUrl9(); void testSetUri9();
void testSetUrl10(); void testSetUri10();
void testSetUrl11(); void testSetUri11();
void testSetUrl12(); void testSetUri12();
void testSetUrl13(); void testSetUri13();
void testSetUrl14(); void testSetUri14();
void testSetUrl15(); void testSetUri15();
void testSetUrl16(); void testSetUri16();
void testSetUrl17(); void testSetUri17();
void testSetUrl18(); void testSetUri18();
void testSetUrl19(); void testSetUri19();
void testSetUrl20(); void testSetUri20();
void testSetUrl_username(); void testSetUri_username();
void testSetUrl_usernamePassword(); void testSetUri_usernamePassword();
void testSetUrl_zeroUsername(); void testSetUri_zeroUsername();
void testSetUrl_supportsPersistentConnection(); void testSetUri_supportsPersistentConnection();
void testSetUrl_ipv6(); void testSetUri_ipv6();
void testRedirectUrl(); void testRedirectUri();
void testRedirectUrl2(); void testRedirectUri2();
void testRedirectUrl_supportsPersistentConnection(); void testRedirectUri_supportsPersistentConnection();
void testResetUrl(); void testResetUri();
void testResetUrl_supportsPersistentConnection(); void testResetUri_supportsPersistentConnection();
void testInnerLink(); void testInnerLink();
void testInnerLinkInReferer(); void testInnerLinkInReferer();
void testGetURIHost(); void testGetURIHost();
@ -85,14 +85,14 @@ public:
CPPUNIT_TEST_SUITE_REGISTRATION( RequestTest ); CPPUNIT_TEST_SUITE_REGISTRATION( RequestTest );
void RequestTest::testSetUrl1() { void RequestTest::testSetUri1() {
Request req; Request req;
bool v = req.setUrl("http://aria.rednoah.com/"); bool v = req.setUri("http://aria.rednoah.com/");
CPPUNIT_ASSERT(v); CPPUNIT_ASSERT(v);
CPPUNIT_ASSERT_EQUAL(std::string("http://aria.rednoah.com/"), req.getUrl()); CPPUNIT_ASSERT_EQUAL(std::string("http://aria.rednoah.com/"), req.getUri());
CPPUNIT_ASSERT_EQUAL(std::string("http://aria.rednoah.com/"), req.getCurrentUrl()); CPPUNIT_ASSERT_EQUAL(std::string("http://aria.rednoah.com/"), req.getCurrentUri());
CPPUNIT_ASSERT_EQUAL(std::string(""), req.getPreviousUrl()); CPPUNIT_ASSERT_EQUAL(std::string(""), req.getPreviousUri());
CPPUNIT_ASSERT_EQUAL(std::string("http"), req.getProtocol()); CPPUNIT_ASSERT_EQUAL(std::string("http"), req.getProtocol());
CPPUNIT_ASSERT_EQUAL((uint16_t)80, req.getPort()); CPPUNIT_ASSERT_EQUAL((uint16_t)80, req.getPort());
CPPUNIT_ASSERT_EQUAL(std::string("aria.rednoah.com"), req.getHost()); CPPUNIT_ASSERT_EQUAL(std::string("aria.rednoah.com"), req.getHost());
@ -104,17 +104,17 @@ void RequestTest::testSetUrl1() {
CPPUNIT_ASSERT(!req.isIPv6LiteralAddress()); CPPUNIT_ASSERT(!req.isIPv6LiteralAddress());
} }
void RequestTest::testSetUrl2() { void RequestTest::testSetUri2() {
Request req; Request req;
bool v = req.setUrl("http://aria.rednoah.com:8080/index.html"); bool v = req.setUri("http://aria.rednoah.com:8080/index.html");
req.setReferer("http://aria.rednoah.com:8080"); req.setReferer("http://aria.rednoah.com:8080");
CPPUNIT_ASSERT(v); CPPUNIT_ASSERT(v);
// referer is unchaged // referer is unchaged
CPPUNIT_ASSERT_EQUAL(std::string("http://aria.rednoah.com:8080"), req.getReferer()); CPPUNIT_ASSERT_EQUAL(std::string("http://aria.rednoah.com:8080"), req.getReferer());
// previousUrl must equal to referer; // previousUri must equal to referer;
CPPUNIT_ASSERT_EQUAL(req.getReferer(), req.getPreviousUrl()); CPPUNIT_ASSERT_EQUAL(req.getReferer(), req.getPreviousUri());
CPPUNIT_ASSERT_EQUAL(std::string("http"), req.getProtocol()); CPPUNIT_ASSERT_EQUAL(std::string("http"), req.getProtocol());
CPPUNIT_ASSERT_EQUAL((uint16_t)8080, req.getPort()); CPPUNIT_ASSERT_EQUAL((uint16_t)8080, req.getPort());
CPPUNIT_ASSERT_EQUAL(std::string("aria.rednoah.com"), req.getHost()); CPPUNIT_ASSERT_EQUAL(std::string("aria.rednoah.com"), req.getHost());
@ -123,9 +123,9 @@ void RequestTest::testSetUrl2() {
CPPUNIT_ASSERT_EQUAL(std::string(""), req.getQuery()); CPPUNIT_ASSERT_EQUAL(std::string(""), req.getQuery());
} }
void RequestTest::testSetUrl3() { void RequestTest::testSetUri3() {
Request req; Request req;
bool v = req.setUrl("http://aria.rednoah.com/aria2/index.html"); bool v = req.setUri("http://aria.rednoah.com/aria2/index.html");
CPPUNIT_ASSERT(v); CPPUNIT_ASSERT(v);
CPPUNIT_ASSERT_EQUAL(std::string("http"), req.getProtocol()); CPPUNIT_ASSERT_EQUAL(std::string("http"), req.getProtocol());
@ -136,9 +136,9 @@ void RequestTest::testSetUrl3() {
CPPUNIT_ASSERT_EQUAL(std::string(""), req.getQuery()); CPPUNIT_ASSERT_EQUAL(std::string(""), req.getQuery());
} }
void RequestTest::testSetUrl4() { void RequestTest::testSetUri4() {
Request req; Request req;
bool v = req.setUrl("http://aria.rednoah.com/aria2/aria3/index.html"); bool v = req.setUri("http://aria.rednoah.com/aria2/aria3/index.html");
CPPUNIT_ASSERT(v); CPPUNIT_ASSERT(v);
CPPUNIT_ASSERT_EQUAL(std::string("http"), req.getProtocol()); CPPUNIT_ASSERT_EQUAL(std::string("http"), req.getProtocol());
@ -149,9 +149,9 @@ void RequestTest::testSetUrl4() {
CPPUNIT_ASSERT_EQUAL(std::string(""), req.getQuery()); CPPUNIT_ASSERT_EQUAL(std::string(""), req.getQuery());
} }
void RequestTest::testSetUrl5() { void RequestTest::testSetUri5() {
Request req; Request req;
bool v = req.setUrl("http://aria.rednoah.com/aria2/aria3/"); bool v = req.setUri("http://aria.rednoah.com/aria2/aria3/");
CPPUNIT_ASSERT(v); CPPUNIT_ASSERT(v);
CPPUNIT_ASSERT_EQUAL(std::string("http"), req.getProtocol()); CPPUNIT_ASSERT_EQUAL(std::string("http"), req.getProtocol());
@ -162,9 +162,9 @@ void RequestTest::testSetUrl5() {
CPPUNIT_ASSERT_EQUAL(std::string(""), req.getQuery()); CPPUNIT_ASSERT_EQUAL(std::string(""), req.getQuery());
} }
void RequestTest::testSetUrl6() { void RequestTest::testSetUri6() {
Request req; Request req;
bool v = req.setUrl("http://aria.rednoah.com/aria2/aria3"); bool v = req.setUri("http://aria.rednoah.com/aria2/aria3");
CPPUNIT_ASSERT(v); CPPUNIT_ASSERT(v);
CPPUNIT_ASSERT_EQUAL(std::string("http"), req.getProtocol()); CPPUNIT_ASSERT_EQUAL(std::string("http"), req.getProtocol());
@ -175,37 +175,37 @@ void RequestTest::testSetUrl6() {
CPPUNIT_ASSERT_EQUAL(std::string(""), req.getQuery()); CPPUNIT_ASSERT_EQUAL(std::string(""), req.getQuery());
} }
void RequestTest::testSetUrl7() { void RequestTest::testSetUri7() {
Request req; Request req;
bool v = req.setUrl("http://"); bool v = req.setUri("http://");
CPPUNIT_ASSERT(!v); CPPUNIT_ASSERT(!v);
} }
void RequestTest::testSetUrl8() { void RequestTest::testSetUri8() {
Request req; Request req;
bool v = req.setUrl("http:/aria.rednoah.com"); bool v = req.setUri("http:/aria.rednoah.com");
CPPUNIT_ASSERT(!v); CPPUNIT_ASSERT(!v);
} }
void RequestTest::testSetUrl9() { void RequestTest::testSetUri9() {
Request req; Request req;
bool v = req.setUrl("h"); bool v = req.setUri("h");
CPPUNIT_ASSERT(!v); CPPUNIT_ASSERT(!v);
} }
void RequestTest::testSetUrl10() { void RequestTest::testSetUri10() {
Request req; Request req;
bool v = req.setUrl(""); bool v = req.setUri("");
CPPUNIT_ASSERT(!v); CPPUNIT_ASSERT(!v);
} }
void RequestTest::testSetUrl11() { void RequestTest::testSetUri11() {
Request req; Request req;
bool v = req.setUrl("http://host?query/"); bool v = req.setUri("http://host?query/");
CPPUNIT_ASSERT(v); CPPUNIT_ASSERT(v);
CPPUNIT_ASSERT_EQUAL(std::string("http"), req.getProtocol()); CPPUNIT_ASSERT_EQUAL(std::string("http"), req.getProtocol());
@ -215,9 +215,9 @@ void RequestTest::testSetUrl11() {
CPPUNIT_ASSERT_EQUAL(std::string("?query/"), req.getQuery()); CPPUNIT_ASSERT_EQUAL(std::string("?query/"), req.getQuery());
} }
void RequestTest::testSetUrl12() { void RequestTest::testSetUri12() {
Request req; Request req;
bool v = req.setUrl("http://host?query"); bool v = req.setUri("http://host?query");
CPPUNIT_ASSERT(v); CPPUNIT_ASSERT(v);
CPPUNIT_ASSERT_EQUAL(std::string("http"), req.getProtocol()); CPPUNIT_ASSERT_EQUAL(std::string("http"), req.getProtocol());
@ -227,9 +227,9 @@ void RequestTest::testSetUrl12() {
CPPUNIT_ASSERT_EQUAL(std::string("?query"), req.getQuery()); CPPUNIT_ASSERT_EQUAL(std::string("?query"), req.getQuery());
} }
void RequestTest::testSetUrl13() { void RequestTest::testSetUri13() {
Request req; Request req;
bool v = req.setUrl("http://host/?query"); bool v = req.setUri("http://host/?query");
CPPUNIT_ASSERT(v); CPPUNIT_ASSERT(v);
CPPUNIT_ASSERT_EQUAL(std::string("http"), req.getProtocol()); CPPUNIT_ASSERT_EQUAL(std::string("http"), req.getProtocol());
@ -239,9 +239,9 @@ void RequestTest::testSetUrl13() {
CPPUNIT_ASSERT_EQUAL(std::string("?query"), req.getQuery()); CPPUNIT_ASSERT_EQUAL(std::string("?query"), req.getQuery());
} }
void RequestTest::testSetUrl14() { void RequestTest::testSetUri14() {
Request req; Request req;
bool v = req.setUrl("http://host:8080/abc?query"); bool v = req.setUri("http://host:8080/abc?query");
CPPUNIT_ASSERT(v); CPPUNIT_ASSERT(v);
CPPUNIT_ASSERT_EQUAL(std::string("http"), req.getProtocol()); CPPUNIT_ASSERT_EQUAL(std::string("http"), req.getProtocol());
@ -252,11 +252,11 @@ void RequestTest::testSetUrl14() {
CPPUNIT_ASSERT_EQUAL(std::string("?query"), req.getQuery()); CPPUNIT_ASSERT_EQUAL(std::string("?query"), req.getQuery());
} }
void RequestTest::testSetUrl15() void RequestTest::testSetUri15()
{ {
Request req; Request req;
// 2 slashes after host name and dir // 2 slashes after host name and dir
bool v = req.setUrl("http://host//dir1/dir2//file"); bool v = req.setUri("http://host//dir1/dir2//file");
CPPUNIT_ASSERT(v); CPPUNIT_ASSERT(v);
CPPUNIT_ASSERT_EQUAL(std::string("http"), req.getProtocol()); CPPUNIT_ASSERT_EQUAL(std::string("http"), req.getProtocol());
CPPUNIT_ASSERT_EQUAL(std::string("host"), req.getHost()); CPPUNIT_ASSERT_EQUAL(std::string("host"), req.getHost());
@ -265,11 +265,11 @@ void RequestTest::testSetUrl15()
CPPUNIT_ASSERT_EQUAL(std::string(""), req.getQuery()); CPPUNIT_ASSERT_EQUAL(std::string(""), req.getQuery());
} }
void RequestTest::testSetUrl16() void RequestTest::testSetUri16()
{ {
Request req; Request req;
// 2 slashes before file // 2 slashes before file
bool v = req.setUrl("http://host//file"); bool v = req.setUri("http://host//file");
CPPUNIT_ASSERT(v); CPPUNIT_ASSERT(v);
CPPUNIT_ASSERT_EQUAL(std::string("http"), req.getProtocol()); CPPUNIT_ASSERT_EQUAL(std::string("http"), req.getProtocol());
CPPUNIT_ASSERT_EQUAL(std::string("host"), req.getHost()); CPPUNIT_ASSERT_EQUAL(std::string("host"), req.getHost());
@ -278,10 +278,10 @@ void RequestTest::testSetUrl16()
CPPUNIT_ASSERT_EQUAL(std::string(""), req.getQuery()); CPPUNIT_ASSERT_EQUAL(std::string(""), req.getQuery());
} }
void RequestTest::testSetUrl17() void RequestTest::testSetUri17()
{ {
Request req; Request req;
bool v = req.setUrl("http://host:80/file<with%2 %20space/file with space;param%?a=/?"); bool v = req.setUri("http://host:80/file<with%2 %20space/file with space;param%?a=/?");
CPPUNIT_ASSERT(v); CPPUNIT_ASSERT(v);
CPPUNIT_ASSERT_EQUAL(std::string("http"), req.getProtocol()); CPPUNIT_ASSERT_EQUAL(std::string("http"), req.getProtocol());
CPPUNIT_ASSERT_EQUAL(std::string("host"), req.getHost()); CPPUNIT_ASSERT_EQUAL(std::string("host"), req.getHost());
@ -290,57 +290,57 @@ void RequestTest::testSetUrl17()
CPPUNIT_ASSERT_EQUAL(std::string("?a=/?"), req.getQuery()); CPPUNIT_ASSERT_EQUAL(std::string("?a=/?"), req.getQuery());
CPPUNIT_ASSERT_EQUAL(std::string("http://host:80/file%3Cwith%252%20%20space" CPPUNIT_ASSERT_EQUAL(std::string("http://host:80/file%3Cwith%252%20%20space"
"/file%20with%20space;param%25?a=/?"), "/file%20with%20space;param%25?a=/?"),
req.getCurrentUrl()); req.getCurrentUri());
CPPUNIT_ASSERT_EQUAL(std::string("http://host:80/file<with%2 %20space" CPPUNIT_ASSERT_EQUAL(std::string("http://host:80/file<with%2 %20space"
"/file with space;param%?a=/?"), "/file with space;param%?a=/?"),
req.getUrl()); req.getUri());
} }
void RequestTest::testSetUrl18() { void RequestTest::testSetUri18() {
Request req; Request req;
bool v = req.setUrl("http://1/"); bool v = req.setUri("http://1/");
CPPUNIT_ASSERT(v); CPPUNIT_ASSERT(v);
} }
void RequestTest::testSetUrl19() { void RequestTest::testSetUri19() {
Request req; Request req;
// No host // No host
bool v = req.setUrl("http://user@"); bool v = req.setUri("http://user@");
CPPUNIT_ASSERT(!v); CPPUNIT_ASSERT(!v);
} }
void RequestTest::testSetUrl20() { void RequestTest::testSetUri20() {
Request req; Request req;
bool v; bool v;
// Invalid port // Invalid port
v = req.setUrl("http://localhost:65536"); v = req.setUri("http://localhost:65536");
CPPUNIT_ASSERT(!v); CPPUNIT_ASSERT(!v);
v = req.setUrl("http://localhost:65535"); v = req.setUri("http://localhost:65535");
CPPUNIT_ASSERT(v); CPPUNIT_ASSERT(v);
v = req.setUrl("http://localhost:-80"); v = req.setUri("http://localhost:-80");
CPPUNIT_ASSERT(!v); CPPUNIT_ASSERT(!v);
} }
void RequestTest::testRedirectUrl() { void RequestTest::testRedirectUri() {
Request req; Request req;
req.supportsPersistentConnection(false); req.supportsPersistentConnection(false);
req.setUrl("http://aria.rednoah.com:8080/aria2/index.html"); req.setUri("http://aria.rednoah.com:8080/aria2/index.html");
bool v2 = req.redirectUrl("http://aria.rednoah.co.jp/"); bool v2 = req.redirectUri("http://aria.rednoah.co.jp/");
CPPUNIT_ASSERT(v2); CPPUNIT_ASSERT(v2);
// persistent connection flag is set to be true after redirection // persistent connection flag is set to be true after redirection
CPPUNIT_ASSERT(req.supportsPersistentConnection()); CPPUNIT_ASSERT(req.supportsPersistentConnection());
// url must be the same // uri must be the same
CPPUNIT_ASSERT_EQUAL(std::string("http://aria.rednoah.com:8080/aria2/" CPPUNIT_ASSERT_EQUAL(std::string("http://aria.rednoah.com:8080/aria2/"
"index.html"), "index.html"),
req.getUrl()); req.getUri());
// currentUrl must be updated // currentUri must be updated
CPPUNIT_ASSERT_EQUAL(std::string("http://aria.rednoah.co.jp/"), CPPUNIT_ASSERT_EQUAL(std::string("http://aria.rednoah.co.jp/"),
req.getCurrentUrl()); req.getCurrentUri());
// previousUrl must be "" when redirection // previousUri must be "" when redirection
CPPUNIT_ASSERT_EQUAL(std::string(""), req.getPreviousUrl()); CPPUNIT_ASSERT_EQUAL(std::string(""), req.getPreviousUri());
CPPUNIT_ASSERT_EQUAL(std::string("http"), req.getProtocol()); CPPUNIT_ASSERT_EQUAL(std::string("http"), req.getProtocol());
CPPUNIT_ASSERT_EQUAL(std::string("aria.rednoah.co.jp"), req.getHost()); CPPUNIT_ASSERT_EQUAL(std::string("aria.rednoah.co.jp"), req.getHost());
CPPUNIT_ASSERT_EQUAL((uint16_t)80, req.getPort()); CPPUNIT_ASSERT_EQUAL((uint16_t)80, req.getPort());
@ -351,57 +351,57 @@ void RequestTest::testRedirectUrl() {
CPPUNIT_ASSERT_EQUAL((unsigned int)1, req.getRedirectCount()); CPPUNIT_ASSERT_EQUAL((unsigned int)1, req.getRedirectCount());
// Give abosulute path // Give abosulute path
CPPUNIT_ASSERT(req.redirectUrl("/abspath/to/file")); CPPUNIT_ASSERT(req.redirectUri("/abspath/to/file"));
CPPUNIT_ASSERT_EQUAL(std::string("http://aria.rednoah.co.jp/abspath/to/file"), CPPUNIT_ASSERT_EQUAL(std::string("http://aria.rednoah.co.jp/abspath/to/file"),
req.getCurrentUrl()); req.getCurrentUri());
CPPUNIT_ASSERT_EQUAL((unsigned int)2, req.getRedirectCount()); CPPUNIT_ASSERT_EQUAL((unsigned int)2, req.getRedirectCount());
// Give relative path // Give relative path
CPPUNIT_ASSERT(req.redirectUrl("relativepath/to/file")); CPPUNIT_ASSERT(req.redirectUri("relativepath/to/file"));
CPPUNIT_ASSERT_EQUAL(std::string("http://aria.rednoah.co.jp/abspath/to/" CPPUNIT_ASSERT_EQUAL(std::string("http://aria.rednoah.co.jp/abspath/to/"
"relativepath/to/file"), "relativepath/to/file"),
req.getCurrentUrl()); req.getCurrentUri());
CPPUNIT_ASSERT_EQUAL((unsigned int)3, req.getRedirectCount()); CPPUNIT_ASSERT_EQUAL((unsigned int)3, req.getRedirectCount());
// White space in path and fragment is appended. // White space in path and fragment is appended.
CPPUNIT_ASSERT(req.redirectUrl("http://example.org/white space#aria2")); CPPUNIT_ASSERT(req.redirectUri("http://example.org/white space#aria2"));
CPPUNIT_ASSERT_EQUAL(std::string("http://example.org/white%20space"), CPPUNIT_ASSERT_EQUAL(std::string("http://example.org/white%20space"),
req.getCurrentUrl()); req.getCurrentUri());
} }
void RequestTest::testRedirectUrl2() { void RequestTest::testRedirectUri2() {
Request req; Request req;
req.setUrl("http://aria.rednoah.com/download.html"); req.setUri("http://aria.rednoah.com/download.html");
CPPUNIT_ASSERT_EQUAL(std::string(""), req.getPreviousUrl()); CPPUNIT_ASSERT_EQUAL(std::string(""), req.getPreviousUri());
req.setReferer("http://aria.rednoah.com/"); req.setReferer("http://aria.rednoah.com/");
// previousUrl is updated when referer is specified // previousUri is updated when referer is specified
CPPUNIT_ASSERT_EQUAL(std::string("http://aria.rednoah.com/"), req.getPreviousUrl()); CPPUNIT_ASSERT_EQUAL(std::string("http://aria.rednoah.com/"), req.getPreviousUri());
req.redirectUrl("http://aria.rednoah.com/403.html"); req.redirectUri("http://aria.rednoah.com/403.html");
// previousUrl must be "" when redirection // previousUri must be "" when redirection
CPPUNIT_ASSERT_EQUAL(std::string(""), req.getPreviousUrl()); CPPUNIT_ASSERT_EQUAL(std::string(""), req.getPreviousUri());
// referer is unchagned // referer is unchagned
CPPUNIT_ASSERT_EQUAL(std::string("http://aria.rednoah.com/"), req.getReferer()); CPPUNIT_ASSERT_EQUAL(std::string("http://aria.rednoah.com/"), req.getReferer());
req.redirectUrl("http://aria.rednoah.com/error.html"); req.redirectUri("http://aria.rednoah.com/error.html");
// previousUrl must be "" when redirection // previousUri must be "" when redirection
CPPUNIT_ASSERT_EQUAL(std::string(""), req.getPreviousUrl()); CPPUNIT_ASSERT_EQUAL(std::string(""), req.getPreviousUri());
} }
void RequestTest::testResetUrl() { void RequestTest::testResetUri() {
Request req; Request req;
req.setUrl("http://aria.rednoah.com:8080/aria2/index.html"); req.setUri("http://aria.rednoah.com:8080/aria2/index.html");
req.setReferer("http://aria.rednoah.com:8080/"); req.setReferer("http://aria.rednoah.com:8080/");
req.redirectUrl("ftp://aria.rednoah.co.jp/index_en.html?view=wide"); req.redirectUri("ftp://aria.rednoah.co.jp/index_en.html?view=wide");
bool v3 = req.resetUrl(); bool v3 = req.resetUri();
CPPUNIT_ASSERT(v3); CPPUNIT_ASSERT(v3);
// currentUrl must equal to url // currentUri must equal to uri
CPPUNIT_ASSERT_EQUAL(std::string("http://aria.rednoah.com:8080/aria2/index.html"), req.getUrl()); CPPUNIT_ASSERT_EQUAL(std::string("http://aria.rednoah.com:8080/aria2/index.html"), req.getUri());
CPPUNIT_ASSERT_EQUAL(req.getUrl(), req.getCurrentUrl()); CPPUNIT_ASSERT_EQUAL(req.getUri(), req.getCurrentUri());
// previousUrl must equal to referer // previousUri must equal to referer
CPPUNIT_ASSERT_EQUAL(std::string("http://aria.rednoah.com:8080/"), req.getPreviousUrl()); CPPUNIT_ASSERT_EQUAL(std::string("http://aria.rednoah.com:8080/"), req.getPreviousUri());
// referer is unchanged // referer is unchanged
CPPUNIT_ASSERT_EQUAL(std::string("http://aria.rednoah.com:8080/"), req.getReferer()); CPPUNIT_ASSERT_EQUAL(std::string("http://aria.rednoah.com:8080/"), req.getReferer());
CPPUNIT_ASSERT_EQUAL(std::string("http"), req.getProtocol()); CPPUNIT_ASSERT_EQUAL(std::string("http"), req.getProtocol());
@ -414,13 +414,13 @@ void RequestTest::testResetUrl() {
void RequestTest::testInnerLink() { void RequestTest::testInnerLink() {
Request req; Request req;
bool v = req.setUrl("http://aria.rednoah.com/index.html#download"); bool v = req.setUri("http://aria.rednoah.com/index.html#download");
CPPUNIT_ASSERT(v); CPPUNIT_ASSERT(v);
CPPUNIT_ASSERT_EQUAL(std::string("http://aria.rednoah.com/index.html" CPPUNIT_ASSERT_EQUAL(std::string("http://aria.rednoah.com/index.html"
"#download"), "#download"),
req.getUrl()); req.getUri());
CPPUNIT_ASSERT_EQUAL(std::string("http://aria.rednoah.com/index.html"), CPPUNIT_ASSERT_EQUAL(std::string("http://aria.rednoah.com/index.html"),
req.getCurrentUrl()); req.getCurrentUri());
CPPUNIT_ASSERT_EQUAL(std::string("index.html"), req.getFile()); CPPUNIT_ASSERT_EQUAL(std::string("index.html"), req.getFile());
CPPUNIT_ASSERT_EQUAL(std::string(""), req.getQuery()); CPPUNIT_ASSERT_EQUAL(std::string(""), req.getQuery());
} }
@ -432,10 +432,10 @@ void RequestTest::testInnerLinkInReferer() {
req.getReferer()); req.getReferer());
} }
void RequestTest::testSetUrl_zeroUsername() void RequestTest::testSetUri_zeroUsername()
{ {
Request req; Request req;
CPPUNIT_ASSERT(req.setUrl("ftp://@localhost/download/aria2-1.0.0.tar.bz2")); CPPUNIT_ASSERT(req.setUri("ftp://@localhost/download/aria2-1.0.0.tar.bz2"));
CPPUNIT_ASSERT_EQUAL(std::string("ftp"), req.getProtocol()); CPPUNIT_ASSERT_EQUAL(std::string("ftp"), req.getProtocol());
CPPUNIT_ASSERT_EQUAL((uint16_t)21, req.getPort()); CPPUNIT_ASSERT_EQUAL((uint16_t)21, req.getPort());
CPPUNIT_ASSERT_EQUAL(std::string("localhost"), req.getHost()); CPPUNIT_ASSERT_EQUAL(std::string("localhost"), req.getHost());
@ -444,7 +444,7 @@ void RequestTest::testSetUrl_zeroUsername()
CPPUNIT_ASSERT_EQUAL(std::string(""), req.getUsername()); CPPUNIT_ASSERT_EQUAL(std::string(""), req.getUsername());
CPPUNIT_ASSERT_EQUAL(std::string(""), req.getPassword()); CPPUNIT_ASSERT_EQUAL(std::string(""), req.getPassword());
CPPUNIT_ASSERT(req.setUrl("ftp://:@localhost/download/aria2-1.0.0.tar.bz2")); CPPUNIT_ASSERT(req.setUri("ftp://:@localhost/download/aria2-1.0.0.tar.bz2"));
CPPUNIT_ASSERT_EQUAL(std::string("ftp"), req.getProtocol()); CPPUNIT_ASSERT_EQUAL(std::string("ftp"), req.getProtocol());
CPPUNIT_ASSERT_EQUAL((uint16_t)21, req.getPort()); CPPUNIT_ASSERT_EQUAL((uint16_t)21, req.getPort());
CPPUNIT_ASSERT_EQUAL(std::string("localhost"), req.getHost()); CPPUNIT_ASSERT_EQUAL(std::string("localhost"), req.getHost());
@ -453,7 +453,7 @@ void RequestTest::testSetUrl_zeroUsername()
CPPUNIT_ASSERT_EQUAL(std::string(""), req.getUsername()); CPPUNIT_ASSERT_EQUAL(std::string(""), req.getUsername());
CPPUNIT_ASSERT_EQUAL(std::string(""), req.getPassword()); CPPUNIT_ASSERT_EQUAL(std::string(""), req.getPassword());
CPPUNIT_ASSERT(req.setUrl("ftp://:pass@localhost/download/aria2-1.0.0.tar.bz2")); CPPUNIT_ASSERT(req.setUri("ftp://:pass@localhost/download/aria2-1.0.0.tar.bz2"));
CPPUNIT_ASSERT_EQUAL(std::string("ftp"), req.getProtocol()); CPPUNIT_ASSERT_EQUAL(std::string("ftp"), req.getProtocol());
CPPUNIT_ASSERT_EQUAL((uint16_t)21, req.getPort()); CPPUNIT_ASSERT_EQUAL((uint16_t)21, req.getPort());
CPPUNIT_ASSERT_EQUAL(std::string("localhost"), req.getHost()); CPPUNIT_ASSERT_EQUAL(std::string("localhost"), req.getHost());
@ -464,10 +464,10 @@ void RequestTest::testSetUrl_zeroUsername()
} }
void RequestTest::testSetUrl_username() void RequestTest::testSetUri_username()
{ {
Request req; Request req;
CPPUNIT_ASSERT(req.setUrl("ftp://aria2user@localhost/download/aria2-1.0.0.tar.bz2")); CPPUNIT_ASSERT(req.setUri("ftp://aria2user@localhost/download/aria2-1.0.0.tar.bz2"));
CPPUNIT_ASSERT_EQUAL(std::string("ftp"), req.getProtocol()); CPPUNIT_ASSERT_EQUAL(std::string("ftp"), req.getProtocol());
CPPUNIT_ASSERT_EQUAL((uint16_t)21, req.getPort()); CPPUNIT_ASSERT_EQUAL((uint16_t)21, req.getPort());
CPPUNIT_ASSERT_EQUAL(std::string("localhost"), req.getHost()); CPPUNIT_ASSERT_EQUAL(std::string("localhost"), req.getHost());
@ -477,10 +477,10 @@ void RequestTest::testSetUrl_username()
CPPUNIT_ASSERT_EQUAL(std::string(""), req.getPassword()); CPPUNIT_ASSERT_EQUAL(std::string(""), req.getPassword());
} }
void RequestTest::testSetUrl_usernamePassword() void RequestTest::testSetUri_usernamePassword()
{ {
Request req; Request req;
CPPUNIT_ASSERT(req.setUrl("ftp://aria2user%40:aria2pass%40@localhost/download/aria2-1.0.0.tar.bz2")); CPPUNIT_ASSERT(req.setUri("ftp://aria2user%40:aria2pass%40@localhost/download/aria2-1.0.0.tar.bz2"));
CPPUNIT_ASSERT_EQUAL(std::string("ftp"), req.getProtocol()); CPPUNIT_ASSERT_EQUAL(std::string("ftp"), req.getProtocol());
CPPUNIT_ASSERT_EQUAL((uint16_t)21, req.getPort()); CPPUNIT_ASSERT_EQUAL((uint16_t)21, req.getPort());
CPPUNIT_ASSERT_EQUAL(std::string("localhost"), req.getHost()); CPPUNIT_ASSERT_EQUAL(std::string("localhost"), req.getHost());
@ -489,51 +489,51 @@ void RequestTest::testSetUrl_usernamePassword()
CPPUNIT_ASSERT_EQUAL(std::string("aria2user@"), req.getUsername()); CPPUNIT_ASSERT_EQUAL(std::string("aria2user@"), req.getUsername());
CPPUNIT_ASSERT_EQUAL(std::string("aria2pass@"), req.getPassword()); CPPUNIT_ASSERT_EQUAL(std::string("aria2pass@"), req.getPassword());
// make sure that after new url is set, username and password are updated. // make sure that after new uri is set, username and password are updated.
CPPUNIT_ASSERT(req.setUrl("ftp://localhost/download/aria2-1.0.0.tar.bz2")); CPPUNIT_ASSERT(req.setUri("ftp://localhost/download/aria2-1.0.0.tar.bz2"));
CPPUNIT_ASSERT_EQUAL(std::string(""), req.getUsername()); CPPUNIT_ASSERT_EQUAL(std::string(""), req.getUsername());
CPPUNIT_ASSERT_EQUAL(std::string(""), req.getPassword()); CPPUNIT_ASSERT_EQUAL(std::string(""), req.getPassword());
} }
void RequestTest::testSetUrl_supportsPersistentConnection() void RequestTest::testSetUri_supportsPersistentConnection()
{ {
Request req; Request req;
CPPUNIT_ASSERT(req.setUrl("http://host/file")); CPPUNIT_ASSERT(req.setUri("http://host/file"));
req.supportsPersistentConnection(false); req.supportsPersistentConnection(false);
CPPUNIT_ASSERT(!req.supportsPersistentConnection()); CPPUNIT_ASSERT(!req.supportsPersistentConnection());
req.setUrl("http://host/file"); req.setUri("http://host/file");
CPPUNIT_ASSERT(req.supportsPersistentConnection()); CPPUNIT_ASSERT(req.supportsPersistentConnection());
} }
void RequestTest::testResetUrl_supportsPersistentConnection() void RequestTest::testResetUri_supportsPersistentConnection()
{ {
Request req; Request req;
CPPUNIT_ASSERT(req.setUrl("http://host/file")); CPPUNIT_ASSERT(req.setUri("http://host/file"));
req.supportsPersistentConnection(false); req.supportsPersistentConnection(false);
CPPUNIT_ASSERT(!req.supportsPersistentConnection()); CPPUNIT_ASSERT(!req.supportsPersistentConnection());
req.resetUrl(); req.resetUri();
CPPUNIT_ASSERT(req.supportsPersistentConnection()); CPPUNIT_ASSERT(req.supportsPersistentConnection());
} }
void RequestTest::testRedirectUrl_supportsPersistentConnection() void RequestTest::testRedirectUri_supportsPersistentConnection()
{ {
Request req; Request req;
CPPUNIT_ASSERT(req.setUrl("http://host/file")); CPPUNIT_ASSERT(req.setUri("http://host/file"));
req.supportsPersistentConnection(false); req.supportsPersistentConnection(false);
CPPUNIT_ASSERT(!req.supportsPersistentConnection()); CPPUNIT_ASSERT(!req.supportsPersistentConnection());
req.redirectUrl("http://host/file"); req.redirectUri("http://host/file");
CPPUNIT_ASSERT(req.supportsPersistentConnection()); CPPUNIT_ASSERT(req.supportsPersistentConnection());
} }
void RequestTest::testSetUrl_ipv6() void RequestTest::testSetUri_ipv6()
{ {
Request req; Request req;
CPPUNIT_ASSERT(!req.setUrl("http://[::1")); CPPUNIT_ASSERT(!req.setUri("http://[::1"));
CPPUNIT_ASSERT(req.setUrl("http://[::1]")); CPPUNIT_ASSERT(req.setUri("http://[::1]"));
CPPUNIT_ASSERT_EQUAL(std::string("::1"), req.getHost()); CPPUNIT_ASSERT_EQUAL(std::string("::1"), req.getHost());
CPPUNIT_ASSERT(req.setUrl("http://[::1]:8000/dir/file")); CPPUNIT_ASSERT(req.setUri("http://[::1]:8000/dir/file"));
CPPUNIT_ASSERT_EQUAL(std::string("::1"), req.getHost()); CPPUNIT_ASSERT_EQUAL(std::string("::1"), req.getHost());
CPPUNIT_ASSERT_EQUAL((uint16_t)8000, req.getPort()); CPPUNIT_ASSERT_EQUAL((uint16_t)8000, req.getPort());
CPPUNIT_ASSERT_EQUAL(std::string("/dir"), req.getDir()); CPPUNIT_ASSERT_EQUAL(std::string("/dir"), req.getDir());
@ -544,7 +544,7 @@ void RequestTest::testSetUrl_ipv6()
void RequestTest::testGetURIHost() void RequestTest::testGetURIHost()
{ {
Request req; Request req;
CPPUNIT_ASSERT(req.setUrl("http://[::1]")); CPPUNIT_ASSERT(req.setUri("http://[::1]"));
CPPUNIT_ASSERT_EQUAL(std::string("[::1]"), req.getURIHost()); CPPUNIT_ASSERT_EQUAL(std::string("[::1]"), req.getURIHost());
} }