mirror of https://github.com/aria2/aria2
Rewritten HttpProxyOptionHandler using uri::parse().
Removed test case where username is empty and resulted URI has empty username in URI.pull/2/head
parent
065fb3a6b8
commit
fc4d38d236
|
@ -56,6 +56,7 @@
|
|||
#include "FileEntry.h"
|
||||
#include "a2io.h"
|
||||
#include "LogFactory.h"
|
||||
#include "uri.h"
|
||||
#ifdef ENABLE_MESSAGE_DIGEST
|
||||
# include "MessageDigest.h"
|
||||
#endif // ENABLE_MESSAGE_DIGEST
|
||||
|
@ -674,36 +675,23 @@ void HttpProxyOptionHandler::parseArg(Option& option, const std::string& optarg)
|
|||
uri = "http://";
|
||||
uri += optarg;
|
||||
}
|
||||
if(!req.setUri(uri)) {
|
||||
uri::UriStruct us;
|
||||
if(!uri::parse(us, uri)) {
|
||||
throw DL_ABORT_EX(_("unrecognized proxy format"));
|
||||
}
|
||||
uri = "http://";
|
||||
if(req.getUsername().empty()) {
|
||||
us.protocol = "http";
|
||||
if(us.username.empty()) {
|
||||
if(option.defined(proxyUserPref_)) {
|
||||
uri += util::percentEncode(option.get(proxyUserPref_));
|
||||
us.username = option.get(proxyUserPref_);
|
||||
}
|
||||
} else {
|
||||
uri += util::percentEncode(req.getUsername());
|
||||
}
|
||||
if(!req.hasPassword()) {
|
||||
if(!us.hasPassword) {
|
||||
if(option.defined(proxyPasswdPref_)) {
|
||||
uri += A2STR::COLON_C;
|
||||
uri += util::percentEncode(option.get(proxyPasswdPref_));
|
||||
us.password = option.get(proxyPasswdPref_);
|
||||
us.hasPassword = true;
|
||||
}
|
||||
} else {
|
||||
uri += A2STR::COLON_C;
|
||||
uri += util::percentEncode(req.getPassword());
|
||||
}
|
||||
if(uri.size() > 7) {
|
||||
uri += "@";
|
||||
}
|
||||
if(req.isIPv6LiteralAddress()) {
|
||||
strappend(uri, "[", req.getHost(), "]");
|
||||
} else {
|
||||
uri += req.getHost();
|
||||
}
|
||||
strappend(uri, A2STR::COLON_C, util::uitos(req.getPort()));
|
||||
option.put(optName_, uri);
|
||||
option.put(optName_, uri::construct(us));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -313,11 +313,11 @@ void OptionHandlerTest::testHttpProxyOptionHandler()
|
|||
CPPUNIT_ASSERT(!handler.canHandle("foobar"));
|
||||
Option option;
|
||||
handler.parse(option, "proxy:65535");
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("http://proxy:65535"),
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("http://proxy:65535/"),
|
||||
option.get(PREF_HTTP_PROXY));
|
||||
|
||||
handler.parse(option, "http://proxy:8080");
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("http://proxy:8080"),
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("http://proxy:8080/"),
|
||||
option.get(PREF_HTTP_PROXY));
|
||||
|
||||
handler.parse(option, "");
|
||||
|
@ -332,32 +332,31 @@ void OptionHandlerTest::testHttpProxyOptionHandler()
|
|||
handler.createPossibleValuesString());
|
||||
|
||||
handler.parse(option, "http://user%40:passwd%40@proxy:8080");
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("http://user%40:passwd%40@proxy:8080"),
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("http://user%40:passwd%40@proxy:8080/"),
|
||||
option.get(PREF_HTTP_PROXY));
|
||||
|
||||
option.put(PREF_HTTP_PROXY_USER, "proxy@user");
|
||||
handler.parse(option, "http://proxy:8080");
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("http://proxy%40user@proxy:8080"),
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("http://proxy%40user@proxy:8080/"),
|
||||
option.get(PREF_HTTP_PROXY));
|
||||
|
||||
option.put(PREF_HTTP_PROXY_PASSWD, "proxy@passwd");
|
||||
handler.parse(option, "http://proxy:8080");
|
||||
CPPUNIT_ASSERT_EQUAL
|
||||
(std::string("http://proxy%40user:proxy%40passwd@proxy:8080"),
|
||||
(std::string("http://proxy%40user:proxy%40passwd@proxy:8080/"),
|
||||
option.get(PREF_HTTP_PROXY));
|
||||
|
||||
handler.parse(option, "http://user:passwd@proxy:8080");
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("http://user:passwd@proxy:8080"),
|
||||
option.get(PREF_HTTP_PROXY));
|
||||
|
||||
option.put(PREF_HTTP_PROXY_USER, "");
|
||||
handler.parse(option, "http://proxy:8080");
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("http://:proxy%40passwd@proxy:8080"),
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("http://user:passwd@proxy:8080/"),
|
||||
option.get(PREF_HTTP_PROXY));
|
||||
|
||||
option.put(PREF_HTTP_PROXY_PASSWD, "");
|
||||
handler.parse(option, "http://proxy:8080");
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("http://:@proxy:8080"),
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("http://proxy%40user:@proxy:8080/"),
|
||||
option.get(PREF_HTTP_PROXY));
|
||||
|
||||
handler.parse(option, "http://[::1]:8080");
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("http://proxy%40user:@[::1]:8080/"),
|
||||
option.get(PREF_HTTP_PROXY));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue