mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-28 11:31:53 +01:00
backport changes from 1.4.3 branch
This commit is contained in:
@@ -69,29 +69,20 @@ HTTPBasicCredentials::HTTPBasicCredentials(const std::string& username, const st
|
||||
|
||||
HTTPBasicCredentials::HTTPBasicCredentials(const HTTPRequest& request)
|
||||
{
|
||||
static const int eof = std::char_traits<char>::eof();
|
||||
std::string scheme;
|
||||
std::string authInfo;
|
||||
request.getCredentials(scheme, authInfo);
|
||||
if (icompare(scheme, SCHEME) == 0)
|
||||
{
|
||||
parseAuthInfo(authInfo);
|
||||
}
|
||||
else throw NotAuthenticatedException("Basic authentication expected");
|
||||
}
|
||||
|
||||
std::string scheme;
|
||||
std::string info;
|
||||
request.getCredentials(scheme, info);
|
||||
if (icompare(scheme, SCHEME) == 0)
|
||||
{
|
||||
std::istringstream istr(info);
|
||||
Base64Decoder decoder(istr);
|
||||
int ch = decoder.get();
|
||||
while (ch != eof && ch != ':')
|
||||
{
|
||||
_username += (char) ch;
|
||||
ch = decoder.get();
|
||||
}
|
||||
if (ch == ':') ch = decoder.get();
|
||||
while (ch != eof)
|
||||
{
|
||||
_password += (char) ch;
|
||||
ch = decoder.get();
|
||||
}
|
||||
}
|
||||
else throw NotAuthenticatedException("Basic authentication expected");
|
||||
|
||||
HTTPBasicCredentials::HTTPBasicCredentials(const std::string& authInfo)
|
||||
{
|
||||
parseAuthInfo(authInfo);
|
||||
}
|
||||
|
||||
|
||||
@@ -123,4 +114,25 @@ void HTTPBasicCredentials::authenticate(HTTPRequest& request)
|
||||
}
|
||||
|
||||
|
||||
void HTTPBasicCredentials::parseAuthInfo(const std::string& authInfo)
|
||||
{
|
||||
static const int eof = std::char_traits<char>::eof();
|
||||
|
||||
std::istringstream istr(authInfo);
|
||||
Base64Decoder decoder(istr);
|
||||
int ch = decoder.get();
|
||||
while (ch != eof && ch != ':')
|
||||
{
|
||||
_username += (char) ch;
|
||||
ch = decoder.get();
|
||||
}
|
||||
if (ch == ':') ch = decoder.get();
|
||||
while (ch != eof)
|
||||
{
|
||||
_password += (char) ch;
|
||||
ch = decoder.get();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Net
|
||||
|
||||
Reference in New Issue
Block a user