diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2009-01-30 16:12:41 +0000 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2009-01-30 16:12:41 +0000 |
| commit | e5c4b24454a37ad6eb5eae3a0685115e4078a06a (patch) | |
| tree | 16138c045553f9c1df8d71a14a62101640b0bf32 /src/HttpRequest.cc | |
| parent | 120ea4c609b28c7fd3d907f1fa689737df92b8ef (diff) | |
2009-01-31 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Send HTTP Authorization header only if it is requested by the
server(response 401). There are some exceptions. The
authorization header for proxy is always sent if it is available
without request by the server. If username/password is specified
in the URI, it is immediately sent to the server without
request by the server.
AbstractAuthResolver::_defaultAuthConfig is now initialized as
SharedHandle<AuthConfig>().
NetrcAuthResolver::resolveAuthConfig() returns
SharedHandle<AuthConfig>() if no AuthConfig is available.
* src/AbstractAuthResolver.cc
* src/AbstractProxyRequestCommand.cc
* src/AuthConfigFactory.cc
* src/AuthConfigFactory.h
* src/HttpConnection.cc
* src/HttpRequest.cc
* src/HttpRequest.h
* src/HttpResponse.cc
* src/HttpResponseCommand.cc
* src/HttpSkipResponseCommand.cc
* test/AuthConfigFactoryTest.cc
* test/HttpRequestTest.cc
* test/HttpResponseTest.cc
Diffstat (limited to 'src/HttpRequest.cc')
| -rw-r--r-- | src/HttpRequest.cc | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/src/HttpRequest.cc b/src/HttpRequest.cc index 4c582116..bce4fd40 100644 --- a/src/HttpRequest.cc +++ b/src/HttpRequest.cc @@ -132,18 +132,17 @@ std::string HttpRequest::getHostText(const std::string& host, uint16_t port) con return host+(port == 80 || port == 443 ? "" : ":"+Util::uitos(port)); } -std::string HttpRequest::createRequest() const +std::string HttpRequest::createRequest() { - SharedHandle<AuthConfig> authConfig = - _authConfigFactory->createAuthConfig(request); + _authConfig = _authConfigFactory->createAuthConfig(request); std::string requestLine = request->getMethod()+" "; if(!_proxyRequest.isNull()) { if(getProtocol() == Request::PROTO_FTP && - request->getUsername().empty() && !authConfig->getUser().empty()) { + request->getUsername().empty() && !_authConfig.isNull()) { // Insert user into URI, like ftp://USER@host/ std::string uri = getCurrentURI(); assert(uri.size() >= 6); - uri.insert(6, Util::urlencode(authConfig->getUser())+"@"); + uri.insert(6, Util::urlencode(_authConfig->getUser())+"@"); requestLine += uri; } else { requestLine += getCurrentURI(); @@ -204,9 +203,9 @@ std::string HttpRequest::createRequest() const if(!_proxyRequest.isNull() && !_proxyRequest->getUsername().empty()) { requestLine += getProxyAuthString(); } - if(!authConfig->getUser().empty()) { + if(!_authConfig.isNull()) { requestLine += "Authorization: Basic "+ - Base64::encode(authConfig->getAuthText())+"\r\n"; + Base64::encode(_authConfig->getAuthText())+"\r\n"; } if(getPreviousURI().size()) { requestLine += "Referer: "+getPreviousURI()+"\r\n"; @@ -360,4 +359,14 @@ bool HttpRequest::isProxyRequestSet() const return !_proxyRequest.isNull(); } +bool HttpRequest::authenticationUsed() const +{ + return !_authConfig.isNull(); +} + +const SharedHandle<AuthConfig>& HttpRequest::getAuthConfig() const +{ + return _authConfig; +} + } // namespace aria2 |
