本文整理汇总了C++中NameValueCollection::find方法的典型用法代码示例。如果您正苦于以下问题:C++ NameValueCollection::find方法的具体用法?C++ NameValueCollection::find怎么用?C++ NameValueCollection::find使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NameValueCollection
的用法示例。
在下文中一共展示了NameValueCollection::find方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getId
std::string WebSessionManager::getId(const std::string& appName, const Poco::Net::HTTPServerRequest& request)
{
std::string id;
std::string name(cookieName(appName));
NameValueCollection cookies;
request.getCookies(cookies);
NameValueCollection::ConstIterator it = cookies.find(name);
if (it != cookies.end())
id = it->second;
return id;
}
示例2: isValidRequest
//------------------------------------------------------------------------------
bool ofxWebServerBaseRouteHandler::isValidRequest(const Settings& settings,
HTTPServerRequest& request,
HTTPServerResponse& response) {
string sessionId = "";
// extract cookie from request
NameValueCollection cookies;
request.getCookies(cookies);
NameValueCollection::ConstIterator it = cookies.find(settings.sessionCookieName);
if (it != cookies.end()) {
sessionId = it->second;
} else {
sessionId = ofxWebServerSessionManager::generateSessionKey(request);
HTTPCookie cookie(settings.sessionCookieName,sessionId);
cookie.setPath("/");
// set no age, so it expires @ end of session
response.addCookie(cookie);
}
// TODO: update session manager
URI uri(request.getURI());
const string path = uri.getPath(); // just get the path
if(settings.requireAuthentication) {
if(request.hasCredentials()) {
HTTPBasicCredentials credentials(request);
const string& user = credentials.getUsername();
const string& pwd = credentials.getPassword();
if(settings.username == credentials.getUsername() &&
settings.password == credentials.getPassword()) {
// add an authentication cookie?
return true;
} else {
response.setStatusAndReason(HTTPResponse::HTTP_UNAUTHORIZED);
sendErrorResponse(response);
return false;
}
} else {
response.requireAuthentication(settings.realm);
response.setContentLength(0);
response.send();
return false;
}
} else {
return true;
}
}
示例3: testNameValueCollection
void NameValueCollectionTest::testNameValueCollection()
{
NameValueCollection nvc;
assert (nvc.empty());
assert (nvc.size() == 0);
nvc.set("name", "value");
assert (!nvc.empty());
assert (nvc["name"] == "value");
assert (nvc["Name"] == "value");
nvc.set("name2", "value2");
assert (nvc.get("name2") == "value2");
assert (nvc.get("NAME2") == "value2");
assert (nvc.size() == 2);
try
{
std::string value = nvc.get("name3");
fail("not found - must throw");
}
catch (NotFoundException&)
{
}
try
{
std::string value = nvc["name3"];
fail("not found - must throw");
}
catch (NotFoundException&)
{
}
assert (nvc.get("name", "default") == "value");
assert (nvc.get("name3", "default") == "default");
assert (nvc.has("name"));
assert (nvc.has("name2"));
assert (!nvc.has("name3"));
nvc.add("name3", "value3");
assert (nvc.get("name3") == "value3");
nvc.add("name3", "value31");
NameValueCollection::ConstIterator it = nvc.find("Name3");
assert (it != nvc.end());
std::string v1 = it->second;
assert (it->first == "name3");
++it;
assert (it != nvc.end());
std::string v2 = it->second;
assert (it->first == "name3");
assert ((v1 == "value3" && v2 == "value31") || (v1 == "value31" && v2 == "value3"));
nvc.erase("name3");
assert (!nvc.has("name3"));
assert (nvc.find("name3") == nvc.end());
it = nvc.begin();
assert (it != nvc.end());
++it;
assert (it != nvc.end());
++it;
assert (it == nvc.end());
nvc.clear();
assert (nvc.empty());
assert (nvc.size() == 0);
}