diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2011-11-13 23:06:24 +0900 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2011-11-13 23:06:24 +0900 |
| commit | 97a9242cbe618ac3c2e3e89c30ee8018268e35a3 (patch) | |
| tree | 59f54d46282273e7986a3055b31c49e1514dbff5 /src/AbstractCommand.cc | |
| parent | c42dd7e75539754f34269c46ad7673881ddbbf0d (diff) | |
Proxy URI is now constructed in getProxyUri().
The previous implementation constructs proxy URI in OptionHandler but
it cannot handle with the situation when user, password and proxy URI
is given various order. Now we just set rules: username set in
--*-proxy-user overrides username in --*-proxy option, no matter in
any order username, password and proxy URI are parsed. Likewise,
password set in --*--proxy-passwd overrides password in --*-proxy
option.
Diffstat (limited to 'src/AbstractCommand.cc')
| -rw-r--r-- | src/AbstractCommand.cc | 68 |
1 files changed, 52 insertions, 16 deletions
diff --git a/src/AbstractCommand.cc b/src/AbstractCommand.cc index d658d657..118cebb9 100644 --- a/src/AbstractCommand.cc +++ b/src/AbstractCommand.cc @@ -543,35 +543,72 @@ void AbstractCommand::setWriteCheckSocketIf } namespace { -// Returns proxy option value for the given protocol. -const std::string& getProxyOptionFor -(const Pref* proxyPref, const SharedHandle<Option>& option) +// Constructs proxy URI, merging username and password if they are +// defined. +std::string makeProxyUri +(const Pref* proxyPref, + const Pref* proxyUser, + const Pref* proxyPasswd, + const Option* option) { - if(option->defined(proxyPref)) { - return option->get(proxyPref); + uri::UriStruct us; + if(uri::parse(us, option->get(proxyPref))) { + if(option->defined(proxyUser)) { + us.username = option->get(proxyUser); + } + if(option->defined(proxyPasswd)) { + us.password = option->get(proxyPasswd); + us.hasPassword = true; + } + return uri::construct(us); } else { - return option->get(PREF_ALL_PROXY); + return ""; } } } // namespace namespace { +// Returns proxy option value for the given protocol. +std::string getProxyOptionFor +(const Pref* proxyPref, + const Pref* proxyUser, + const Pref* proxyPasswd, + const Option* option) +{ + std::string uri = makeProxyUri(proxyPref, proxyUser, proxyPasswd, option); + if(uri.empty()) { + return makeProxyUri(PREF_ALL_PROXY, PREF_ALL_PROXY_USER, + PREF_ALL_PROXY_PASSWD, option); + } else { + return uri; + } +} +} // namespace + // Returns proxy URI for given protocol. If no proxy URI is defined, // then returns an empty string. -const std::string& getProxyUri -(const std::string& protocol, const SharedHandle<Option>& option) +std::string getProxyUri +(const std::string& protocol, const Option* option) { if(protocol == Request::PROTO_HTTP) { - return getProxyOptionFor(PREF_HTTP_PROXY, option); + return getProxyOptionFor(PREF_HTTP_PROXY, + PREF_HTTP_PROXY_USER, + PREF_HTTP_PROXY_PASSWD, + option); } else if(protocol == Request::PROTO_HTTPS) { - return getProxyOptionFor(PREF_HTTPS_PROXY, option); + return getProxyOptionFor(PREF_HTTPS_PROXY, + PREF_HTTPS_PROXY_USER, + PREF_HTTPS_PROXY_PASSWD, + option); } else if(protocol == Request::PROTO_FTP) { - return getProxyOptionFor(PREF_FTP_PROXY, option); + return getProxyOptionFor(PREF_FTP_PROXY, + PREF_FTP_PROXY_USER, + PREF_FTP_PROXY_PASSWD, + option); } else { return A2STR::NIL; } } -} // namespace namespace { // Returns true if proxy is defined for the given protocol. Otherwise @@ -579,9 +616,8 @@ namespace { bool isProxyRequest (const std::string& protocol, const SharedHandle<Option>& option) { - const std::string& proxyUri = getProxyUri(protocol, option); - uri::UriStruct us; - return !proxyUri.empty() && uri::parse(us, proxyUri); + std::string proxyUri = getProxyUri(protocol, option.get()); + return !proxyUri.empty(); } } // namespace @@ -635,7 +671,7 @@ SharedHandle<Request> AbstractCommand::createProxyRequest() const if(inNoProxy(req_, getOption()->get(PREF_NO_PROXY))) { return proxyRequest; } - std::string proxy = getProxyUri(req_->getProtocol(), getOption()); + std::string proxy = getProxyUri(req_->getProtocol(), getOption().get()); if(!proxy.empty()) { proxyRequest.reset(new Request()); if(proxyRequest->setUri(proxy)) { |
