本文整理汇总了C++中HTTPServerRequest类的典型用法代码示例。如果您正苦于以下问题:C++ HTTPServerRequest类的具体用法?C++ HTTPServerRequest怎么用?C++ HTTPServerRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HTTPServerRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: editScriptPage
void HTTPServerRequestDespatcher::editScriptPage(HTTPServerRequest &request, std::string &response)
{
if (request.isPost()) // actual submission
{
std::string thisResponse;
if (editScriptScheduledTestPage(m_pMonitoringDB, request, thisResponse))
{
// okay
HTTPServerRedirectResponse resp("/monitoring");
response = resp.responseString();
}
else
{
HTTPServerResponse resp(500, thisResponse);
response = resp.responseString();
}
}
else // otherwise, serve up the edit form
{
std::string templatePath = m_webContentPath + "form.tplt";
std::string title = "Edit Script Page";
std::string formContent;
long testID = atoi(request.getParam("page_id").c_str());
generateEditScriptScheduledTestPageForm(m_pMonitoringDB, testID, formContent);
HTTPServerTemplateFileResponse resp(templatePath, title, formContent);
response = resp.responseString();
}
}
示例2: 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;
}
}
}
示例3: choose
RequestSelector::Selection LocalSelector::choose(const HTTPServerRequest& request) const
{
if (request.clientAddress().host().isLoopback() || request.clientAddress().host().isSiteLocal())
{
return {true, false, 1};
}
return {false,false,0};
}
示例4: runManualScriptTest
void HTTPServerRequestDespatcher::runManualScriptTest(HTTPServerRequest &request, std::string &response)
{
if (request.isPost())
{
unsigned long testID = request.getParamAsLong("test_id");
if (testID != -1)
{
::runManualScriptTest(m_pMonitoringDB, m_pResultsSaver, testID);
}
}
}
示例5: scriptDetails
void HTTPServerRequestDespatcher::scriptDetails(HTTPServerRequest &request, std::string &response)
{
long testID = atoi(request.getParam("test_id").c_str());
long runID = atoi(request.getParam("run_id").c_str());
std::string filePath = m_webContentPath + "script_details.tplt";
std::string dataContent;
getScriptScheduledTestResultsDetails(m_pMonitoringDB, testID, runID, dataContent);
HTTPServerTemplateFileResponse resp(filePath, dataContent);
response = resp.responseString();
}
示例6: handleRequest
virtual void handleRequest(HTTPServerRequest &req, HTTPServerResponse &resp){
resp.setStatus(HTTPResponse::HTTP_OK);
resp.setContentType("text/html");
// Generate requested HTML file
ostream& out = resp.send();
out << "<h1>Hello world! This files name is " << req.getURI() << "</h1>"
<< "<p>Host: " << req.getHost() << "</p>"
<< "<p>Method: " << req.getMethod() << "</p>";
out.flush();
cout << endl << "Client requested: =" << req.getURI() << endl;
}
示例7: singleComponents
void HTTPServerRequestDespatcher::singleComponents(HTTPServerRequest &request, std::string &response)
{
long runID = atoi(request.getParam("run_id").c_str());
long testID = atoi(request.getParam("test_id").c_str());
std::string filePath = m_webContentPath + "single_components.tplt";
std::string dataContent;
getSingleScheduledTestComponentsList(m_pMonitoringDB, testID, runID, dataContent);
HTTPServerTemplateFileResponse resp(filePath, dataContent);
response = resp.responseString();
}
示例8: 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;
}
}
示例9: history
void HTTPServerRequestDespatcher::history(HTTPServerRequest &request, std::string &response)
{
int offset = 0;
if (request.hasParams())
{
offset = atoi(request.getParam("start").c_str());
}
std::string filePath = m_webContentPath + "history.tplt";
std::string dataContent;
getSingleTestHistoryList(m_pMonitoringDB, dataContent, offset);
HTTPServerTemplateFileResponse resp(filePath, dataContent);
response = resp.responseString();
}
示例10: addScriptTest
void HTTPServerRequestDespatcher::addScriptTest(HTTPServerRequest &request, std::string &response)
{
if (request.isPost()) // actual submission
{
std::string thisResponse;
if (addScriptScheduledTest(m_pMonitoringDB, request, thisResponse))
{
// okay
HTTPServerRedirectResponse resp("/monitoring");
response = resp.responseString();
}
else
{
HTTPServerResponse resp(500, thisResponse);
response = resp.responseString();
}
}
else // otherwise, serve up the entry form
{
std::string templatePath = m_webContentPath + "form.tplt";
std::string title = "Add Script Test";
std::string formContent;
generateAddScriptScheduledTestForm(formContent);
HTTPServerTemplateFileResponse resp(templatePath, title, formContent);
response = resp.responseString();
}
}
示例11: handleRequest
void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response)
{
Application& app = Application::instance();
app.logger().information("Request from " + request.clientAddress().toString());
SecureStreamSocket socket = static_cast<HTTPServerRequestImpl&>(request).socket();
if (socket.havePeerCertificate())
{
X509Certificate cert = socket.peerCertificate();
app.logger().information("Client certificate: " + cert.subjectName());
}
else
{
app.logger().information("No client certificate available.");
}
Timestamp now;
std::string dt(DateTimeFormatter::format(now, _format));
response.setChunkedTransferEncoding(true);
response.setContentType("text/html");
std::ostream& ostr = response.send();
ostr << "<html><head><title>HTTPTimeServer powered by POCO C++ Libraries</title>";
ostr << "<meta http-equiv=\"refresh\" content=\"1\"></head>";
ostr << "<body><p style=\"text-align: center; font-size: 48px;\">";
ostr << dt;
ostr << "</p></body></html>";
}
示例12: handleRequest
void PageRequestHandler::handleRequest(HTTPServerRequest &req, HTTPServerResponse &resp) {
resp.setStatus(HTTPResponse::HTTP_OK);
// std::cout << Poco::format("Received request %s", req.getURI()) << std::endl;
string fileName = req.getURI() == "/" ? "index.html" : (req.getURI().substr(1));
if (stringEndsWith(fileName, ".html")) {
resp.setContentType("text/html");
} else if (stringEndsWith(fileName, ".css")) {
resp.setContentType("text/css");
} else if (stringEndsWith(fileName, ".js")) {
resp.setContentType("application/javascript");
} else if (stringEndsWith(fileName, ".woff")) {
resp.setContentType("font/woff");
} else {
resp.setContentType("text/html");
}
FileInputStream input(fileName);
StreamCopier::copyStream(input, resp.send());
}
示例13: handleRequest
void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response)
{
response.setContentType("text/html");
response.setChunkedTransferEncoding(true);
std::ostream& ostr = response.send();
const std::string& softwareVersion = request.serverParams().getSoftwareVersion();
LocalDateTime now;
std::string osName = Environment::osName();
std::string osDisplayName = Environment::osDisplayName();
if (osDisplayName != osName)
{
osName += " (";
osName += osDisplayName;
osName += ")";
}
ostr << "<HTML><HEAD><TITLE>Server Information</TITLE>"
"<LINK REL=\"stylesheet\" HREF=\"css/styles.css\" TYPE=\"text/css\"/></HEAD><BODY>"
"<DIV CLASS=\"header\">"
"<H1 CLASS=\"category\">Open Service Platform</h1>"
"<H1 CLASS=\"title\">Server Information</H1>"
"</DIV>"
"<DIV CLASS=\"body\">"
"<UL>";
ostr << "<LI><B>Host:</B> " << Environment::nodeName() << "</LI>"
<< "<LI><B>Node ID:</B> " << Environment::nodeId() << "</LI>"
<< "<LI><B>IP Addresses:</B> " << getHostAddresses() << "</LI>"
<< "<LI><B>OS Name:</B> " << osName << "</LI>"
<< "<LI><B>OS Version:</B> " << Environment::osVersion() << "</LI>"
<< "<LI><B>OS Architecture:</B> " << Environment::osArchitecture() << "</LI>"
<< "<LI><B>Processor Cores:</B> " << Environment::processorCount() << "</LI>"
<< "<LI><B>Local Server Time:</B> " << DateTimeFormatter::format(now, DateTimeFormat::HTTP_FORMAT) << "</LI>"
<< "<LI><B>Server Process ID:</B> " << Process::id() << "</LI>";
ostr << "</UL><HR><P>";
ostr << htmlize(softwareVersion) << " at " << request.serverAddress().toString();
ostr << "</P></DIV></BODY></HTML>";
}
示例14: handleRequest
void AddBook::handleRequest(HTTPServerRequest& req, HTTPServerResponse& resp)
{
URI uri(req.getURI());
std::string book = getParam(uri.getQueryParameters(), HttpParam::Book);
std::vector<std::string> authors = parseAuthors(getParam(uri.getQueryParameters(), HttpParam::Authors));
if (book.empty() || authors.empty())
send(resp, HTTPResponse::HTTP_BAD_REQUEST, "Bad request!\n");
else
addBook(book, authors, resp);
}
示例15: singleDetails
void HTTPServerRequestDespatcher::singleDetails(HTTPServerRequest &request, std::string &response)
{
long runID = atoi(request.getParam("runid").c_str());
std::string filePath = m_webContentPath + "single_details.tplt";
std::string dataContent;
formatDBSingleTestResponseToHTMLDL(m_pMonitoringDB, runID, dataContent);
HTTPServerTemplateFileResponse resp(filePath, dataContent);
response = resp.responseString();
}