本文整理汇总了C++中WebServer::getHostAddress方法的典型用法代码示例。如果您正苦于以下问题:C++ WebServer::getHostAddress方法的具体用法?C++ WebServer::getHostAddress怎么用?C++ WebServer::getHostAddress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WebServer
的用法示例。
在下文中一共展示了WebServer::getHostAddress方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: runWebServerTest
static void runWebServerTest(TestRunner& tr)
{
const char* path = "/test";
const char* content = "web server test";
const char* regexPath = "/test/dumplings/regextest/turkey";
const char* regexPath2 = "/test/dumplings/regextest2/turkey";
const char* regexPath3 = "/test/dumplings/regextest3/turkey";
const char* regexContent = "web server test (regex)";
// create kernel
Kernel k;
// set thread stack size in engine (128k)
k.getEngine()->getThreadPool()->setThreadStackSize(131072);
// optional for testing --
// limit threads to 2: one for accepting, 1 for handling
//k.getEngine()->getThreadPool()->setPoolSize(2);
// start engine
k.getEngine()->start();
// create server
Server server;
WebServer ws;
Config cfg;
cfg["host"] = "localhost";
cfg["port"] = 0;
cfg["security"] = "off";
WebServiceContainerRef wsc = new WebServiceContainer();
ws.setContainer(wsc);
ws.initialize(cfg);
WebServiceRef tws = new TestWebService(path, content, regexContent);
wsc->addService(tws, WebService::Both);
ws.enable(&server);
// start server
assertNoException(server.start(&k));
// get server port
int port = ws.getHostAddress()->getPort();
// check the regular path and data
tr.test("WebServer - regular path handler");
{
Url url;
url.format("http://%s:%d%s", cfg["host"]->getString(), port, path);
_checkUrlText(tr, &url, 200, content, strlen(content));
}
tr.passIfNoException();
// check the regex path and data
tr.test("WebServer - regex path handler");
{
Url url;
url.format("http://%s:%d%s", cfg["host"]->getString(), port, regexPath);
_checkUrlText(tr, &url, 200, regexContent, strlen(regexContent));
}
tr.passIfNoException();
// check the regex path and data
tr.test("WebServer - regex path handler matches");
{
DynamicObject info;
info["type"] = "monarch.ws.RestfulHandler";
DynamicObject& matches = info["matches"];
matches[0] = "dumplings";
matches[1] = "turkey";
string expect = JsonWriter::writeToString(info);
Url url;
url.format("http://%s:%d%s", cfg["host"]->getString(), port, regexPath2);
_checkUrlText(tr, &url, 200, expect.c_str(), expect.length());
}
tr.passIfNoException();
// check the web service authentication exception
tr.test("WebServer - authentication exception");
{
DynamicObject ex;
ex["message"] = "WebService authentication failed. Access denied.";
ex["type"] = "monarch.ws.AccessDenied";
ex["details"]["httpStatusCode"] = 403;
ex["details"]["path"] = "/test/dumplings/regextest3/turkey";
ex["details"]["public"] = true;
DynamicObject& cause = ex["cause"];
cause["message"] = "Tried to authenticate but failed.";
cause["type"] = "tests.ws.Exception";
string expect = JsonWriter::writeToString(ex, true);
Url url;
url.format("http://%s:%d%s", cfg["host"]->getString(), port, regexPath3);
_checkUrlText(tr, &url, 400, expect.c_str(), expect.length());
}
tr.passIfNoException();
server.stop();
// stop kernel engine
//.........这里部分代码省略.........