mirror of https://github.com/aria2/aria2
Join URI on redirect
parent
4a106e7fcf
commit
f022444d81
|
@ -131,17 +131,7 @@ bool Request::redirectUri(const std::string& uri) {
|
||||||
// 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.
|
||||||
// UPDATE: draft-ietf-httpbis-p2-semantics-18 now allows this.
|
// UPDATE: draft-ietf-httpbis-p2-semantics-18 now allows this.
|
||||||
uri::UriStruct rus(us_);
|
redirectedUri = uri::joinUri(currentUri_, uri);
|
||||||
rus.query.clear();
|
|
||||||
rus.file.clear();
|
|
||||||
size_t offset = 0;
|
|
||||||
if(uri[0] == '/') {
|
|
||||||
// abosulute path
|
|
||||||
rus.dir.clear();
|
|
||||||
offset = 1;
|
|
||||||
}
|
|
||||||
redirectedUri = uri::construct(rus);
|
|
||||||
redirectedUri.append(uri.begin()+offset, uri.end());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return parseUri(redirectedUri);
|
return parseUri(redirectedUri);
|
||||||
|
|
|
@ -19,6 +19,7 @@ class RequestTest:public CppUnit::TestFixture {
|
||||||
CPPUNIT_TEST(testRedirectUri);
|
CPPUNIT_TEST(testRedirectUri);
|
||||||
CPPUNIT_TEST(testRedirectUri2);
|
CPPUNIT_TEST(testRedirectUri2);
|
||||||
CPPUNIT_TEST(testRedirectUri_supportsPersistentConnection);
|
CPPUNIT_TEST(testRedirectUri_supportsPersistentConnection);
|
||||||
|
CPPUNIT_TEST(testRedirectUri_uriNormalization);
|
||||||
CPPUNIT_TEST(testResetUri);
|
CPPUNIT_TEST(testResetUri);
|
||||||
CPPUNIT_TEST(testResetUri_supportsPersistentConnection);
|
CPPUNIT_TEST(testResetUri_supportsPersistentConnection);
|
||||||
CPPUNIT_TEST(testInnerLink);
|
CPPUNIT_TEST(testInnerLink);
|
||||||
|
@ -34,6 +35,7 @@ public:
|
||||||
void testRedirectUri();
|
void testRedirectUri();
|
||||||
void testRedirectUri2();
|
void testRedirectUri2();
|
||||||
void testRedirectUri_supportsPersistentConnection();
|
void testRedirectUri_supportsPersistentConnection();
|
||||||
|
void testRedirectUri_uriNormalization();
|
||||||
void testResetUri();
|
void testResetUri();
|
||||||
void testResetUri_supportsPersistentConnection();
|
void testResetUri_supportsPersistentConnection();
|
||||||
void testInnerLink();
|
void testInnerLink();
|
||||||
|
@ -255,6 +257,31 @@ void RequestTest::testRedirectUri_supportsPersistentConnection()
|
||||||
CPPUNIT_ASSERT(req.supportsPersistentConnection());
|
CPPUNIT_ASSERT(req.supportsPersistentConnection());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RequestTest::testRedirectUri_uriNormalization()
|
||||||
|
{
|
||||||
|
Request req;
|
||||||
|
CPPUNIT_ASSERT(req.setUri("http://host/file?a"));
|
||||||
|
|
||||||
|
CPPUNIT_ASSERT(req.redirectUri("/redir1"));
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string("http://host/redir1"), req.getCurrentUri());
|
||||||
|
|
||||||
|
CPPUNIT_ASSERT(req.redirectUri("/redir2?b"));
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string("http://host/redir2?b"),
|
||||||
|
req.getCurrentUri());
|
||||||
|
|
||||||
|
CPPUNIT_ASSERT(req.redirectUri("/redir3?c#d"));
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string("http://host/redir3?c"),
|
||||||
|
req.getCurrentUri());
|
||||||
|
|
||||||
|
CPPUNIT_ASSERT(req.redirectUri("/redir4/gone/.././2nd/foo?a"));
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string("http://host/redir4/2nd/foo?a"),
|
||||||
|
req.getCurrentUri());
|
||||||
|
|
||||||
|
CPPUNIT_ASSERT(req.redirectUri("../new2nd/bar?b"));
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string("http://host/redir4/new2nd/bar?b"),
|
||||||
|
req.getCurrentUri());
|
||||||
|
}
|
||||||
|
|
||||||
void RequestTest::testGetURIHost()
|
void RequestTest::testGetURIHost()
|
||||||
{
|
{
|
||||||
Request req;
|
Request req;
|
||||||
|
|
Loading…
Reference in New Issue