本文整理汇总了C++中HTTPServerRequest::get方法的典型用法代码示例。如果您正苦于以下问题:C++ HTTPServerRequest::get方法的具体用法?C++ HTTPServerRequest::get怎么用?C++ HTTPServerRequest::get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HTTPServerRequest
的用法示例。
在下文中一共展示了HTTPServerRequest::get方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: handleRequest
void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response)
{
Application& app = Application::instance();
try
{
std::string proto = request.get("Sec-WebSocket-Protocol", "");
Poco::SharedPtr<Poco::Net::WebSocket> pWebSocket;
if (proto == "com.appinf.webtunnel.server/1.0")
{
response.set("Sec-WebSocket-Protocol", proto);
pWebSocket = new Poco::Net::WebSocket(request, response);
_portReflector.addServerSocket(pWebSocket, "ac9667bb-6032-4267-af61-9a7aafd40479");
}
else if (proto == "com.appinf.webtunnel.client/1.0")
{
response.set("Sec-WebSocket-Protocol", proto);
std::string portStr = request.get("X-WebTunnel-RemotePort", "");
unsigned port;
if (!portStr.empty() && Poco::NumberParser::tryParseUnsigned(portStr, port) && port > 0 && port < 65536)
{
pWebSocket = new Poco::Net::WebSocket(request, response);
try
{
_portReflector.addClientSocket(pWebSocket, "ac9667bb-6032-4267-af61-9a7aafd40479", static_cast<Poco::UInt16>(port));
}
catch (Poco::NotFoundException&)
{
pWebSocket->shutdown(Poco::Net::WebSocket::WS_UNEXPECTED_CONDITION, "No connection to target available");
}
}
else
{
pWebSocket = new Poco::Net::WebSocket(request, response);
pWebSocket->shutdown(Poco::Net::WebSocket::WS_UNEXPECTED_CONDITION, "Missing or invalid X-WebTunnel-RemotePort header");
}
}
else
{
pWebSocket = new Poco::Net::WebSocket(request, response);
pWebSocket->shutdown(Poco::Net::WebSocket::WS_PROTOCOL_ERROR);
}
}
catch (WebSocketException& exc)
{
app.logger().log(exc);
switch (exc.code())
{
case Poco::Net::WebSocket::WS_ERR_HANDSHAKE_UNSUPPORTED_VERSION:
response.set("Sec-WebSocket-Version", WebSocket::WEBSOCKET_VERSION);
// fallthrough
case Poco::Net::WebSocket::WS_ERR_NO_HANDSHAKE:
case Poco::Net::WebSocket::WS_ERR_HANDSHAKE_NO_VERSION:
case Poco::Net::WebSocket::WS_ERR_HANDSHAKE_NO_KEY:
response.setStatusAndReason(HTTPResponse::HTTP_BAD_REQUEST);
response.setContentLength(0);
response.send();
break;
}
}
}