当前位置: 首页>>代码示例>>C++>>正文


C++ HTTPServerRequest类代码示例

本文整理汇总了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();
	}
}
开发者ID:ppearson,项目名称:sitemon2,代码行数:32,代码来源:http_server_request_despatcher.cpp

示例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;
			}
		}
	}
开发者ID:macchina-io,项目名称:macchina.io,代码行数:60,代码来源:WebTunnelReflector.cpp

示例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};   
}
开发者ID:piokra,项目名称:screaming-jazz,代码行数:9,代码来源:LocalSelector.cpp

示例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);
		}
	}
}
开发者ID:ppearson,项目名称:sitemon2,代码行数:12,代码来源:http_server_request_despatcher.cpp

示例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();
}
开发者ID:ppearson,项目名称:sitemon2,代码行数:13,代码来源:http_server_request_despatcher.cpp

示例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;  
 }
开发者ID:ClaytonSmith,项目名称:CPP-HTTP-1.0-Server,代码行数:13,代码来源:server.cpp

示例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();
}
开发者ID:ppearson,项目名称:sitemon2,代码行数:13,代码来源:http_server_request_despatcher.cpp

示例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;
    }
}
开发者ID:bakercp,项目名称:ofxWebServer,代码行数:52,代码来源:ofxWebServerBaseRouteHandler.cpp

示例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();
}
开发者ID:ppearson,项目名称:sitemon2,代码行数:16,代码来源:http_server_request_despatcher.cpp

示例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();
	}
}
开发者ID:ppearson,项目名称:sitemon2,代码行数:29,代码来源:http_server_request_despatcher.cpp

示例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>";
	}
开发者ID:BrianHoldsworth,项目名称:Poco,代码行数:29,代码来源:HTTPSTimeServer.cpp

示例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());
 }
开发者ID:saglam,项目名称:sketch,代码行数:19,代码来源:PageRequestHandler.cpp

示例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>";
	}
开发者ID:macchina-io,项目名称:macchina.io,代码行数:41,代码来源:WebInfo.cpp

示例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);
}
开发者ID:snip777,项目名称:netlib,代码行数:12,代码来源:AddBook.cpp

示例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();
}
开发者ID:ppearson,项目名称:sitemon2,代码行数:12,代码来源:http_server_request_despatcher.cpp


注:本文中的HTTPServerRequest类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。