mirror of https://github.com/aria2/aria2
2008-04-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Removed query part from filename in HTTP download. The query part means the substring after "?" in URL. Firefox seems do the same thing. A query part is sometimes very long and not suitable to filename, so I think it is better to remove it from filename. * src/HttpRequest.cc * src/HttpRequest.h * src/Request.cc * src/Request.h * test/HttpRequestTest.cc * test/RequestTest.ccpull/1/head
parent
1ef99931e1
commit
4663902500
13
ChangeLog
13
ChangeLog
|
@ -1,3 +1,16 @@
|
|||
2008-04-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||
|
||||
Removed query part from filename in HTTP download. The query part means
|
||||
the substring after "?" in URL. Firefox seems do the same thing.
|
||||
A query part is sometimes very long and not suitable to filename,
|
||||
so I think it is better to remove it from filename.
|
||||
* src/HttpRequest.cc
|
||||
* src/HttpRequest.h
|
||||
* src/Request.cc
|
||||
* src/Request.h
|
||||
* test/HttpRequestTest.cc
|
||||
* test/RequestTest.cc
|
||||
|
||||
2008-04-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||
|
||||
Rewritten Exception class. Throw exception object, not its pointer and
|
||||
|
|
|
@ -141,7 +141,7 @@ std::string HttpRequest::createRequest() const
|
|||
} else {
|
||||
requestLine += getDir()+"/";
|
||||
}
|
||||
requestLine += getFile();
|
||||
requestLine += getFile()+getQuery();
|
||||
}
|
||||
requestLine +=
|
||||
std::string(" HTTP/1.1\r\n")+
|
||||
|
@ -281,4 +281,9 @@ std::string HttpRequest::getFile() const
|
|||
return request->getFile();
|
||||
}
|
||||
|
||||
std::string HttpRequest::getQuery() const
|
||||
{
|
||||
return request->getQuery();
|
||||
}
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -108,6 +108,8 @@ public:
|
|||
|
||||
std::string getFile() const;
|
||||
|
||||
std::string getQuery() const;
|
||||
|
||||
std::string getPreviousURI() const;
|
||||
|
||||
SharedHandle<Range> getRange() const;
|
||||
|
|
|
@ -88,12 +88,14 @@ bool Request::parseUrl(const std::string& url) {
|
|||
port = 0;
|
||||
dir = "";
|
||||
file = "";
|
||||
_query = "";
|
||||
_username = "";
|
||||
_password = "";
|
||||
// find query part
|
||||
std::string queryTemp;
|
||||
std::string::size_type startQueryIndex = tempUrl.find("?");
|
||||
if(startQueryIndex != std::string::npos) {
|
||||
query = tempUrl.substr(startQueryIndex);
|
||||
queryTemp = tempUrl.substr(startQueryIndex);
|
||||
tempUrl.erase(startQueryIndex);
|
||||
}
|
||||
// find protocol
|
||||
|
@ -154,7 +156,7 @@ bool Request::parseUrl(const std::string& url) {
|
|||
if(tempUrl.size() > direp+1) {
|
||||
file = tempUrl.substr(direp+1);
|
||||
}
|
||||
file += query;
|
||||
_query = queryTemp;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -69,6 +69,8 @@ private:
|
|||
uint16_t port;
|
||||
std::string dir;
|
||||
std::string file;
|
||||
/* after ? mark(includes '?' itself) */
|
||||
std::string _query;
|
||||
unsigned int tryCount;
|
||||
|
||||
// whether or not the server supports persistent connection
|
||||
|
@ -119,6 +121,7 @@ public:
|
|||
uint16_t getPort() const { return port; }
|
||||
std::string getDir() const { return dir; }
|
||||
std::string getFile() const { return file;}
|
||||
std::string getQuery() const { return _query; }
|
||||
|
||||
void supportsPersistentConnection(bool f)
|
||||
{
|
||||
|
|
|
@ -19,6 +19,7 @@ class HttpRequestTest : public CppUnit::TestFixture {
|
|||
CPPUNIT_TEST(testCreateRequest);
|
||||
CPPUNIT_TEST(testCreateRequest_ftp);
|
||||
CPPUNIT_TEST(testCreateRequest_with_cookie);
|
||||
CPPUNIT_TEST(testCreateRequest_query);
|
||||
CPPUNIT_TEST(testCreateProxyRequest);
|
||||
CPPUNIT_TEST(testIsRangeSatisfied);
|
||||
CPPUNIT_TEST(testUserAgent);
|
||||
|
@ -34,6 +35,7 @@ public:
|
|||
void testCreateRequest();
|
||||
void testCreateRequest_ftp();
|
||||
void testCreateRequest_with_cookie();
|
||||
void testCreateRequest_query();
|
||||
void testCreateProxyRequest();
|
||||
void testIsRangeSatisfied();
|
||||
void testUserAgent();
|
||||
|
@ -457,6 +459,26 @@ void HttpRequestTest::testCreateRequest_with_cookie()
|
|||
|
||||
}
|
||||
|
||||
void HttpRequestTest::testCreateRequest_query()
|
||||
{
|
||||
SharedHandle<Request> request(new Request());
|
||||
request->setUrl("http://localhost/wiki?id=9ad5109a-b8a5-4edf-9373-56a1c34ae138");
|
||||
HttpRequest httpRequest;
|
||||
httpRequest.setRequest(request);
|
||||
|
||||
std::string expectedText =
|
||||
"GET /wiki?id=9ad5109a-b8a5-4edf-9373-56a1c34ae138 HTTP/1.1\r\n"
|
||||
"User-Agent: aria2\r\n"
|
||||
"Accept: */*\r\n"
|
||||
"Host: localhost\r\n"
|
||||
"Pragma: no-cache\r\n"
|
||||
"Cache-Control: no-cache\r\n"
|
||||
"Connection: close\r\n"
|
||||
"\r\n";
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(expectedText, httpRequest.createRequest());
|
||||
}
|
||||
|
||||
void HttpRequestTest::testCreateProxyRequest()
|
||||
{
|
||||
SharedHandle<Request> request(new Request());
|
||||
|
|
|
@ -78,6 +78,7 @@ void RequestTest::testSetUrl1() {
|
|||
CPPUNIT_ASSERT_EQUAL(std::string("aria.rednoah.com"), req.getHost());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("/"), req.getDir());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string(""), req.getFile());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string(""), req.getQuery());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string(""), req.getUsername());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string(""), req.getPassword());
|
||||
}
|
||||
|
@ -98,6 +99,7 @@ void RequestTest::testSetUrl2() {
|
|||
CPPUNIT_ASSERT_EQUAL(std::string("aria.rednoah.com"), req.getHost());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("/"), req.getDir());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("index.html"), req.getFile());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string(""), req.getQuery());
|
||||
}
|
||||
|
||||
void RequestTest::testSetUrl3() {
|
||||
|
@ -110,6 +112,7 @@ void RequestTest::testSetUrl3() {
|
|||
CPPUNIT_ASSERT_EQUAL(std::string("aria.rednoah.com"), req.getHost());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("/aria2"), req.getDir());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("index.html"), req.getFile());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string(""), req.getQuery());
|
||||
}
|
||||
|
||||
void RequestTest::testSetUrl4() {
|
||||
|
@ -122,6 +125,7 @@ void RequestTest::testSetUrl4() {
|
|||
CPPUNIT_ASSERT_EQUAL(std::string("aria.rednoah.com"), req.getHost());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("/aria2/aria3"), req.getDir());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("index.html"), req.getFile());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string(""), req.getQuery());
|
||||
}
|
||||
|
||||
void RequestTest::testSetUrl5() {
|
||||
|
@ -134,6 +138,7 @@ void RequestTest::testSetUrl5() {
|
|||
CPPUNIT_ASSERT_EQUAL(std::string("aria.rednoah.com"), req.getHost());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("/aria2/aria3"), req.getDir());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string(""), req.getFile());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string(""), req.getQuery());
|
||||
}
|
||||
|
||||
void RequestTest::testSetUrl6() {
|
||||
|
@ -146,6 +151,7 @@ void RequestTest::testSetUrl6() {
|
|||
CPPUNIT_ASSERT_EQUAL(std::string("aria.rednoah.com"), req.getHost());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("/aria2"), req.getDir());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("aria3"), req.getFile());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string(""), req.getQuery());
|
||||
}
|
||||
|
||||
void RequestTest::testSetUrl7() {
|
||||
|
@ -184,7 +190,8 @@ void RequestTest::testSetUrl11() {
|
|||
CPPUNIT_ASSERT_EQUAL(std::string("http"), req.getProtocol());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("host"), req.getHost());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("/"), req.getDir());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("?query/"), req.getFile());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string(""), req.getFile());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("?query/"), req.getQuery());
|
||||
}
|
||||
|
||||
void RequestTest::testSetUrl12() {
|
||||
|
@ -195,7 +202,8 @@ void RequestTest::testSetUrl12() {
|
|||
CPPUNIT_ASSERT_EQUAL(std::string("http"), req.getProtocol());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("host"), req.getHost());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("/"), req.getDir());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("?query"), req.getFile());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string(""), req.getFile());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("?query"), req.getQuery());
|
||||
}
|
||||
|
||||
void RequestTest::testSetUrl13() {
|
||||
|
@ -206,7 +214,8 @@ void RequestTest::testSetUrl13() {
|
|||
CPPUNIT_ASSERT_EQUAL(std::string("http"), req.getProtocol());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("host"), req.getHost());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("/"), req.getDir());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("?query"), req.getFile());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string(""), req.getFile());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("?query"), req.getQuery());
|
||||
}
|
||||
|
||||
void RequestTest::testSetUrl14() {
|
||||
|
@ -218,7 +227,8 @@ void RequestTest::testSetUrl14() {
|
|||
CPPUNIT_ASSERT_EQUAL(std::string("host"), req.getHost());
|
||||
CPPUNIT_ASSERT_EQUAL((uint16_t)8080, req.getPort());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("/"), req.getDir());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("abc?query"), req.getFile());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("abc"), req.getFile());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("?query"), req.getQuery());
|
||||
}
|
||||
|
||||
void RequestTest::testSetUrl15()
|
||||
|
@ -231,6 +241,7 @@ void RequestTest::testSetUrl15()
|
|||
CPPUNIT_ASSERT_EQUAL(std::string("host"), req.getHost());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("/dir1/dir2"), req.getDir());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("file"), req.getFile());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string(""), req.getQuery());
|
||||
}
|
||||
|
||||
void RequestTest::testSetUrl16()
|
||||
|
@ -243,6 +254,7 @@ void RequestTest::testSetUrl16()
|
|||
CPPUNIT_ASSERT_EQUAL(std::string("host"), req.getHost());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("/"), req.getDir());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("file"), req.getFile());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string(""), req.getQuery());
|
||||
}
|
||||
|
||||
void RequestTest::testSetUrl17()
|
||||
|
@ -253,7 +265,8 @@ void RequestTest::testSetUrl17()
|
|||
CPPUNIT_ASSERT_EQUAL(std::string("http"), req.getProtocol());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("host"), req.getHost());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("/file%3cwith%252%20%20space"), req.getDir());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("file%20with%20space;param?a=/?"), req.getFile());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("file%20with%20space;param"), req.getFile());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("?a=/?"), req.getQuery());
|
||||
}
|
||||
|
||||
void RequestTest::testRedirectUrl() {
|
||||
|
@ -277,6 +290,7 @@ void RequestTest::testRedirectUrl() {
|
|||
CPPUNIT_ASSERT_EQUAL((uint16_t)80, req.getPort());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("/"), req.getDir());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string(""), req.getFile());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string(""), req.getQuery());
|
||||
}
|
||||
|
||||
void RequestTest::testRedirectUrl2() {
|
||||
|
@ -303,7 +317,7 @@ void RequestTest::testResetUrl() {
|
|||
Request req;
|
||||
req.setUrl("http://aria.rednoah.com:8080/aria2/index.html");
|
||||
req.setReferer("http://aria.rednoah.com:8080/");
|
||||
req.redirectUrl("ftp://aria.rednoah.co.jp/");
|
||||
req.redirectUrl("ftp://aria.rednoah.co.jp/index_en.html?view=wide");
|
||||
|
||||
bool v3 = req.resetUrl();
|
||||
CPPUNIT_ASSERT(v3);
|
||||
|
@ -319,6 +333,7 @@ void RequestTest::testResetUrl() {
|
|||
CPPUNIT_ASSERT_EQUAL(std::string("aria.rednoah.com"), req.getHost());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("/aria2"), req.getDir());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("index.html"), req.getFile());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string(""), req.getQuery());
|
||||
}
|
||||
|
||||
void RequestTest::testInnerLink() {
|
||||
|
@ -326,6 +341,7 @@ void RequestTest::testInnerLink() {
|
|||
bool v = req.setUrl("http://aria.rednoah.com/index.html#download");
|
||||
CPPUNIT_ASSERT(v);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("index.html"), req.getFile());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string(""), req.getQuery());
|
||||
}
|
||||
|
||||
void RequestTest::testSetUrl_zeroUsername()
|
||||
|
|
Loading…
Reference in New Issue