本文整理汇总了C++中poco::net::HTTPServerResponse::sendBuffer方法的典型用法代码示例。如果您正苦于以下问题:C++ HTTPServerResponse::sendBuffer方法的具体用法?C++ HTTPServerResponse::sendBuffer怎么用?C++ HTTPServerResponse::sendBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类poco::net::HTTPServerResponse
的用法示例。
在下文中一共展示了HTTPServerResponse::sendBuffer方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: handleRequest
void handleRequest(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response) {
jsonrpc::handleRequest(response, [&](){
HttpServerHelpers::ReturnType ret = HttpServerHelpers::preprocess(p, request, response);
if (ret == HttpServerHelpers::RequestFinished){
return;
}
std::string serviceName = request.getURI();
std::cout << "servicename before: " << serviceName << std::endl;
if (serviceName.find('/') == 0) {
serviceName = serviceName.substr(1);
}
std::string::size_type question = serviceName.find('?');
if (question != std::string::npos) {
serviceName = serviceName.substr(0, question);
}
std::cout << "servicename after: " << serviceName << std::endl;
for (auto i = p.getRequestHandlers().begin(); i != p.getRequestHandlers().end(); i++){
if ((*i)->canHandle(serviceName)){
std::cout << "SPECIAL HANDLING of " << serviceName << std::endl;
(*i)->handle(request, response);
return;
}
}
//std::cout << "service name: " << serviceName << std::endl;
std::istream& rs = request.stream();
std::stringstream outstr;
Poco::StreamCopier::copyStream(rs, outstr);
std::string rsp;
std::string req = outstr.str();
//std::cout << "requset: " << req << std::endl;
//this->handlerProvider.GetHandler()
LTRACE("Json") << "request " << req << LE;
if (auto sHandlerProvider = handlerProvider.lock()) {
sHandlerProvider->getHandler(serviceName)->HandleRequest(req, rsp);
} else {
throw Poco::Exception("Request refused - server destroyed");
}
LTRACE("Json") << "response " << rsp << LE;
//std::cout << "response: " << rsp << std::endl;
response.setContentType("application/json");
response.sendBuffer(rsp.data(), rsp.length());
});
}
示例2: handleRequest
void ReplicasStatusHandler::handleRequest(Poco::Net::HTTPServerRequest & request, Poco::Net::HTTPServerResponse & response)
{
try
{
HTMLForm params(request);
/// Даже в случае, когда отставание небольшое, выводить подробную информацию об отставании.
bool verbose = params.get("verbose", "") == "1";
const MergeTreeSettings & settings = context.getMergeTreeSettings();
bool ok = true;
std::stringstream message;
auto databases = context.getDatabases();
/// Перебираем все реплицируемые таблицы.
for (const auto & db : databases)
{
for (auto iterator = db.second->getIterator(); iterator->isValid(); iterator->next())
{
auto & table = iterator->table();
StorageReplicatedMergeTree * table_replicated = typeid_cast<StorageReplicatedMergeTree *>(table.get());
if (!table_replicated)
continue;
time_t absolute_delay = 0;
time_t relative_delay = 0;
table_replicated->getReplicaDelays(absolute_delay, relative_delay);
if ((settings.min_absolute_delay_to_close && absolute_delay >= static_cast<time_t>(settings.min_absolute_delay_to_close))
|| (settings.min_relative_delay_to_close && relative_delay >= static_cast<time_t>(settings.min_relative_delay_to_close)))
ok = false;
message << backQuoteIfNeed(db.first) << "." << backQuoteIfNeed(iterator->name())
<< ":\tAbsolute delay: " << absolute_delay << ". Relative delay: " << relative_delay << ".\n";
}
}
setResponseDefaultHeaders(response);
if (ok && !verbose)
{
const char * data = "Ok.\n";
response.sendBuffer(data, strlen(data));
}
else
{
response.send() << message.rdbuf();
}
}
catch (...)
{
tryLogCurrentException("ReplicasStatusHandler");
try
{
response.setStatusAndReason(Poco::Net::HTTPResponse::HTTP_INTERNAL_SERVER_ERROR);
if (!response.sent())
{
/// Ещё ничего не отправляли, и даже не знаем, нужно ли сжимать ответ.
response.send() << getCurrentExceptionMessage(false) << std::endl;
}
}
catch (...)
{
LOG_ERROR((&Logger::get("ReplicasStatusHandler")), "Cannot send exception to client");
}
}
}
示例3:
void ofxRemoteUIWebServer::RUIRequestHandler::handleRequest(Poco::Net::HTTPServerRequest &req, Poco::Net::HTTPServerResponse &resp) {
resp.set("Content-Encoding", "gzip");
resp.sendBuffer(RUI_WEB_BINARY_CONTENT, RUI_WEB_BINARY_SIZE);
}