本文整理汇总了C++中HttpHeader::setField方法的典型用法代码示例。如果您正苦于以下问题:C++ HttpHeader::setField方法的具体用法?C++ HttpHeader::setField怎么用?C++ HttpHeader::setField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpHeader
的用法示例。
在下文中一共展示了HttpHeader::setField方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: runCookieTest
static void runCookieTest(TestRunner& tr)
{
tr.group("Http Cookie");
tr.test("parse Set-Cookie header");
{
HttpHeader header;
header.addField("Set-Cookie",
"cookie1_name=cookie1_value; max-age=0; path=/");
header.addField("Set-Cookie",
"cookie2_name=cookie2_value; max-age=0; path=/; secure");
header.addField("Set-Cookie",
"cookie3_name=cookie3_value; max-age=0; path=/; secure");
header.addField("Set-Cookie",
"cookie4_name=cookie4_value; max-age=0; path=/moo");
CookieJar jar;
jar.readCookies(&header, CookieJar::Server);
Cookie cookie1 = jar.getCookie("cookie1_name");
Cookie cookie2 = jar.getCookie("cookie2_name");
Cookie cookie3 = jar.getCookie("cookie3_name");
Cookie cookie4 = jar.getCookie("cookie4_name");
Cookie cookie5 = jar.getCookie("cookie5_name");
assert(!cookie1.isNull());
assert(!cookie2.isNull());
assert(!cookie3.isNull());
assert(!cookie4.isNull());
assert(cookie5.isNull());
assertStrCmp(cookie1["name"]->getString(), "cookie1_name");
assertStrCmp(cookie2["name"]->getString(), "cookie2_name");
assertStrCmp(cookie3["name"]->getString(), "cookie3_name");
assertStrCmp(cookie4["name"]->getString(), "cookie4_name");
assertStrCmp(cookie1["value"]->getString(), "cookie1_value");
assertStrCmp(cookie2["value"]->getString(), "cookie2_value");
assertStrCmp(cookie3["value"]->getString(), "cookie3_value");
assertStrCmp(cookie4["value"]->getString(), "cookie4_value");
assertStrCmp(cookie1["path"]->getString(), "/");
assertStrCmp(cookie2["path"]->getString(), "/");
assertStrCmp(cookie3["path"]->getString(), "/");
assertStrCmp(cookie4["path"]->getString(), "/moo");
assert(!cookie1["secure"]->getBoolean());
assert(cookie2["secure"]->getBoolean());
assert(cookie3["secure"]->getBoolean());
assert(!cookie4["secure"]->getBoolean());
}
tr.passIfNoException();
tr.test("overwrite Set-Cookie header");
{
HttpHeader header;
header.addField(
"Set-Cookie",
"cookie1_name=cookie1_value; max-age=30; path=/");
header.addField(
"Set-Cookie",
"cookie2_name=cookie2_value; max-age=30; path=/; secure");
header.addField(
"Set-Cookie",
"cookie3_name=cookie3_value; max-age=30; path=/");
CookieJar jar;
jar.deleteCookie("cookie2_name", false);
jar.setCookie("cookie4_name", "cookie4_value", 0, true, true);
jar.writeCookies(&header, CookieJar::Server, true);
string cookies;
header.getField("Set-Cookie", cookies, 0);
assertStrCmp(cookies.c_str(),
"cookie2_name=; max-age=0; path=/");
header.getField("Set-Cookie", cookies, 1);
assertStrCmp(cookies.c_str(),
"cookie4_name=cookie4_value; max-age=0; path=/; secure; HttpOnly");
}
tr.passIfNoException();
tr.test("extend Set-Cookie header");
{
HttpHeader header;
header.setField("Set-Cookie",
"cookie1_name=cookie1_value; max-age=0; path=/, "
"cookie2_name=cookie2_value; max-age=0; path=/; secure, "
"cookie3_name=cookie3_value; max-age=0; path=/");
CookieJar jar;
jar.setCookie("cookie4_name", "cookie4_value", 0, true, false);
jar.deleteCookie("cookie5_name", true);
jar.writeCookies(&header, CookieJar::Server, false);
string cookies;
header.getField("Set-Cookie", cookies, 0);
assertStrCmp(cookies.c_str(),
//.........这里部分代码省略.........