mirror of https://github.com/aria2/aria2
Fixed bug that some information such as port number is lost if
redirect URI contains only path component.pull/2/head
parent
0b515d7204
commit
5e2a8b2d4c
|
@ -111,14 +111,17 @@ bool Request::redirectUri(const std::string& uri) {
|
||||||
if(uri.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.
|
||||||
|
uri::UriStruct rus(us_);
|
||||||
|
rus.query.clear();
|
||||||
|
rus.file.clear();
|
||||||
|
size_t offset = 0;
|
||||||
if(uri[0] == '/') {
|
if(uri[0] == '/') {
|
||||||
// abosulute path
|
// abosulute path
|
||||||
redirectedUri = strconcat(us_.protocol, "://", us_.host, uri);
|
rus.dir.clear();
|
||||||
} else {
|
offset = 1;
|
||||||
// relative path
|
|
||||||
redirectedUri = strconcat(us_.protocol, "://", us_.host, us_.dir,
|
|
||||||
"/", uri);
|
|
||||||
}
|
}
|
||||||
|
redirectedUri = uri::construct(rus);
|
||||||
|
redirectedUri.append(uri.begin()+offset, uri.end());
|
||||||
} else {
|
} else {
|
||||||
redirectedUri = uri;
|
redirectedUri = uri;
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,8 +98,13 @@ void RequestTest::testRedirectUri()
|
||||||
req.supportsPersistentConnection(false);
|
req.supportsPersistentConnection(false);
|
||||||
req.setUri("http://aria.rednoah.com:8080/aria2/index.html");
|
req.setUri("http://aria.rednoah.com:8080/aria2/index.html");
|
||||||
|
|
||||||
bool v2 = req.redirectUri("http://aria.rednoah.co.jp/");
|
// See port number is preserved.
|
||||||
CPPUNIT_ASSERT(v2);
|
CPPUNIT_ASSERT(req.redirectUri("/foo"));
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string("http://aria.rednoah.com:8080/foo"),
|
||||||
|
req.getCurrentUri());
|
||||||
|
CPPUNIT_ASSERT_EQUAL((unsigned int)1, req.getRedirectCount());
|
||||||
|
|
||||||
|
CPPUNIT_ASSERT(req.redirectUri("http://aria.rednoah.co.jp/"));
|
||||||
// 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());
|
||||||
// uri must be the same
|
// uri must be the same
|
||||||
|
@ -118,20 +123,20 @@ void RequestTest::testRedirectUri()
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string(""), req.getFile());
|
CPPUNIT_ASSERT_EQUAL(std::string(""), req.getFile());
|
||||||
CPPUNIT_ASSERT_EQUAL(std::string(""), req.getQuery());
|
CPPUNIT_ASSERT_EQUAL(std::string(""), req.getQuery());
|
||||||
// See redirect count is incremented.
|
// See redirect count is incremented.
|
||||||
CPPUNIT_ASSERT_EQUAL((unsigned int)1, req.getRedirectCount());
|
CPPUNIT_ASSERT_EQUAL((unsigned int)2, req.getRedirectCount());
|
||||||
|
|
||||||
// Give abosulute path
|
// Give abosulute path
|
||||||
CPPUNIT_ASSERT(req.redirectUri("/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.getCurrentUri());
|
req.getCurrentUri());
|
||||||
CPPUNIT_ASSERT_EQUAL((unsigned int)2, req.getRedirectCount());
|
CPPUNIT_ASSERT_EQUAL((unsigned int)3, req.getRedirectCount());
|
||||||
|
|
||||||
// Give relative path
|
// Give relative path
|
||||||
CPPUNIT_ASSERT(req.redirectUri("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.getCurrentUri());
|
req.getCurrentUri());
|
||||||
CPPUNIT_ASSERT_EQUAL((unsigned int)3, req.getRedirectCount());
|
CPPUNIT_ASSERT_EQUAL((unsigned int)4, req.getRedirectCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
void RequestTest::testRedirectUri2()
|
void RequestTest::testRedirectUri2()
|
||||||
|
|
Loading…
Reference in New Issue