mirror of https://github.com/aria2/aria2
Include trailing "/" in UriStruct::dir.
The duplicate "/"s in dir are not removed now.pull/4/head
parent
c0dda6a0f7
commit
9e5124eb11
|
@ -154,12 +154,7 @@ std::string HttpRequest::createRequest()
|
|||
requestLine += getCurrentURI();
|
||||
}
|
||||
} else {
|
||||
if(getDir() == A2STR::SLASH_C) {
|
||||
requestLine += getDir();
|
||||
} else {
|
||||
requestLine += getDir();
|
||||
requestLine += A2STR::SLASH_C;
|
||||
}
|
||||
requestLine += getDir();
|
||||
requestLine += getFile();
|
||||
requestLine += getQuery();
|
||||
}
|
||||
|
@ -231,12 +226,7 @@ std::string HttpRequest::createRequest()
|
|||
if(cookieStorage_) {
|
||||
std::string cookiesValue;
|
||||
std::string path = getDir();
|
||||
if(getDir() == "/") {
|
||||
path += getFile();
|
||||
} else {
|
||||
path += "/";
|
||||
path += getFile();
|
||||
}
|
||||
path += getFile();
|
||||
std::vector<Cookie> cookies =
|
||||
cookieStorage_->criteriaFind(getHost(), path,
|
||||
Time().getTime(),
|
||||
|
|
46
src/uri.cc
46
src/uri.cc
|
@ -102,15 +102,15 @@ void swap(UriStruct& lhs, UriStruct& rhs)
|
|||
bool parse(UriStruct& result, const std::string& uri)
|
||||
{
|
||||
// http://user:password@aria2.sourceforge.net:80/dir/file?query#fragment
|
||||
// | || || | | | |
|
||||
// | || hostLast| | | | |
|
||||
// | || portFirst| | | |
|
||||
// authorityFirst || authorityLast | | |
|
||||
// || | | | |
|
||||
// userInfoLast | | | |
|
||||
// | | | | |
|
||||
// hostPortFirst | | | |
|
||||
// | | | |
|
||||
// | || || | | | |
|
||||
// | || hostLast| | | | |
|
||||
// | || portFirst| | | |
|
||||
// authorityFirst || authorityLast | | |
|
||||
// || | | | |
|
||||
// userInfoLast | | | |
|
||||
// | | | | |
|
||||
// hostPortFirst | | | |
|
||||
// | | | |
|
||||
// dirFirst dirLast| |
|
||||
// | |
|
||||
// queryFirst fragmentFirst
|
||||
|
@ -231,32 +231,19 @@ bool parse(UriStruct& result, const std::string& uri)
|
|||
for(std::string::const_iterator i = authorityLast;
|
||||
i != queryFirst; ++i) {
|
||||
if(*i == '/') {
|
||||
dirLast = i;
|
||||
dirLast = i+1;
|
||||
}
|
||||
}
|
||||
if(dirLast == queryFirst) {
|
||||
result.file = A2STR::NIL;
|
||||
} else {
|
||||
result.file.assign(dirLast+1, queryFirst);
|
||||
result.file.assign(dirLast, queryFirst);
|
||||
}
|
||||
// Erase duplicated slashes.
|
||||
std::string::const_iterator dirFirst = authorityLast;
|
||||
for(; dirFirst != dirLast; ++dirFirst) {
|
||||
if(*dirFirst != '/') {
|
||||
--dirFirst;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for(; dirLast != dirFirst; --dirLast) {
|
||||
if(*dirLast != '/') {
|
||||
++dirLast;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(dirFirst == dirLast) {
|
||||
result.dir = A2STR::SLASH_C;
|
||||
// dirFirst == authorityLast
|
||||
if(authorityLast == dirLast) {
|
||||
result.dir = "/";
|
||||
} else {
|
||||
result.dir.assign(dirFirst, dirLast);
|
||||
result.dir.assign(authorityLast, dirLast);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -284,8 +271,7 @@ std::string construct(const UriStruct& us)
|
|||
uint16_t defPort= FeatureConfig::getInstance()->
|
||||
getDefaultPort(us.protocol);
|
||||
if(us.port != 0 && defPort != us.port) {
|
||||
res += ":";
|
||||
res += util::uitos(us.port);
|
||||
res += fmt(":%u", us.port);
|
||||
}
|
||||
res += us.dir;
|
||||
if(us.dir.empty() || us.dir[us.dir.size()-1] != '/') {
|
||||
|
|
|
@ -187,7 +187,7 @@ void RequestTest::testResetUri()
|
|||
CPPUNIT_ASSERT_EQUAL(std::string("http"), req.getProtocol());
|
||||
CPPUNIT_ASSERT_EQUAL((uint16_t)8080, req.getPort());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("aria.rednoah.com"), req.getHost());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("/aria2"), req.getDir());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("/aria2/"), req.getDir());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("index.html"), req.getFile());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string(""), req.getQuery());
|
||||
}
|
||||
|
|
|
@ -111,7 +111,7 @@ void UriTest::testSetUri3()
|
|||
CPPUNIT_ASSERT_EQUAL(std::string("http"), us.protocol);
|
||||
CPPUNIT_ASSERT_EQUAL((uint16_t)80, us.port);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("aria.rednoah.com"), us.host);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("/aria2"), us.dir);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("/aria2/"), us.dir);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("index.html"), us.file);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string(""), us.query);
|
||||
}
|
||||
|
@ -125,7 +125,7 @@ void UriTest::testSetUri4()
|
|||
CPPUNIT_ASSERT_EQUAL(std::string("http"), us.protocol);
|
||||
CPPUNIT_ASSERT_EQUAL((uint16_t)80, us.port);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("aria.rednoah.com"), us.host);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("/aria2/aria3"), us.dir);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("/aria2/aria3/"), us.dir);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("index.html"), us.file);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string(""), us.query);
|
||||
}
|
||||
|
@ -139,7 +139,7 @@ void UriTest::testSetUri5()
|
|||
CPPUNIT_ASSERT_EQUAL(std::string("http"), us.protocol);
|
||||
CPPUNIT_ASSERT_EQUAL((uint16_t)80, us.port);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("aria.rednoah.com"), us.host);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("/aria2/aria3"), us.dir);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("/aria2/aria3/"), us.dir);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string(""), us.file);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string(""), us.query);
|
||||
}
|
||||
|
@ -153,7 +153,7 @@ void UriTest::testSetUri6()
|
|||
CPPUNIT_ASSERT_EQUAL(std::string("http"), us.protocol);
|
||||
CPPUNIT_ASSERT_EQUAL((uint16_t)80, us.port);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("aria.rednoah.com"), us.host);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("/aria2"), us.dir);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("/aria2/"), us.dir);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("aria3"), us.file);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string(""), us.query);
|
||||
}
|
||||
|
@ -251,7 +251,7 @@ void UriTest::testSetUri15()
|
|||
CPPUNIT_ASSERT(v);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("http"), us.protocol);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("host"), us.host);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("/dir1/dir2"), us.dir);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("//dir1/dir2//"), us.dir);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("file"), us.file);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string(""), us.query);
|
||||
}
|
||||
|
@ -264,7 +264,7 @@ void UriTest::testSetUri16()
|
|||
CPPUNIT_ASSERT(v);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("http"), us.protocol);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("host"), us.host);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("/"), us.dir);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("//"), us.dir);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("file"), us.file);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string(""), us.query);
|
||||
}
|
||||
|
@ -306,7 +306,7 @@ void UriTest::testSetUri_zeroUsername()
|
|||
CPPUNIT_ASSERT_EQUAL(std::string("ftp"), us.protocol);
|
||||
CPPUNIT_ASSERT_EQUAL((uint16_t)21, us.port);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("localhost"), us.host);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("/download"), us.dir);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("/download/"), us.dir);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("aria2-1.0.0.tar.bz2"), us.file);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string(""), us.username);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string(""), us.password);
|
||||
|
@ -315,7 +315,7 @@ void UriTest::testSetUri_zeroUsername()
|
|||
CPPUNIT_ASSERT_EQUAL(std::string("ftp"), us.protocol);
|
||||
CPPUNIT_ASSERT_EQUAL((uint16_t)21, us.port);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("localhost"), us.host);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("/download"), us.dir);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("/download/"), us.dir);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("aria2-1.0.0.tar.bz2"), us.file);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string(""), us.username);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string(""), us.password);
|
||||
|
@ -325,7 +325,7 @@ void UriTest::testSetUri_zeroUsername()
|
|||
CPPUNIT_ASSERT_EQUAL(std::string("ftp"), us.protocol);
|
||||
CPPUNIT_ASSERT_EQUAL((uint16_t)21, us.port);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("localhost"), us.host);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("/download"), us.dir);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("/download/"), us.dir);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("aria2-1.0.0.tar.bz2"), us.file);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string(""), us.username);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("pass"), us.password);
|
||||
|
@ -340,7 +340,7 @@ void UriTest::testSetUri_username()
|
|||
CPPUNIT_ASSERT_EQUAL(std::string("ftp"), us.protocol);
|
||||
CPPUNIT_ASSERT_EQUAL((uint16_t)21, us.port);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("localhost"), us.host);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("/download"), us.dir);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("/download/"), us.dir);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("aria2-1.0.0.tar.bz2"), us.file);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("aria2@user"), us.username);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string(""), us.password);
|
||||
|
@ -355,7 +355,7 @@ void UriTest::testSetUri_usernamePassword()
|
|||
CPPUNIT_ASSERT_EQUAL(std::string("ftp"), us.protocol);
|
||||
CPPUNIT_ASSERT_EQUAL((uint16_t)21, us.port);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("localhost"), us.host);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("/download"), us.dir);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("/download/"), us.dir);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("aria2-1.0.0.tar.bz2"), us.file);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("aria2@user@"), us.username);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("aria2@pass@"), us.password);
|
||||
|
@ -376,7 +376,7 @@ void UriTest::testSetUri_ipv6()
|
|||
CPPUNIT_ASSERT(parse(us, "http://[::1]:8000/dir/file"));
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("::1"), us.host);
|
||||
CPPUNIT_ASSERT_EQUAL((uint16_t)8000, us.port);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("/dir"), us.dir);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("/dir/"), us.dir);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("file"), us.file);
|
||||
CPPUNIT_ASSERT(us.ipv6LiteralAddress);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue