本文整理汇总了C++中poco::net::HTTPServerResponse::setReason方法的典型用法代码示例。如果您正苦于以下问题:C++ HTTPServerResponse::setReason方法的具体用法?C++ HTTPServerResponse::setReason怎么用?C++ HTTPServerResponse::setReason使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类poco::net::HTTPServerResponse
的用法示例。
在下文中一共展示了HTTPServerResponse::setReason方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: prepareResponse
void
BufferHandler::handleRequest(Poco::Net::HTTPServerRequest &req, Poco::Net::HTTPServerResponse &resp)
{
prepareResponse(resp);
resp.set("ETag", etag);
resp.set("Cache-Control", "max-age=300, private");
if (req.get("If-None-Match", "") == etag) {
// ETag matched. No content to send;
resp.setStatus(Poco::Net::HTTPResponse::HTTP_NOT_MODIFIED);
resp.setReason("Not Modified");
resp.send().flush();
return;
}
resp.setStatus(Poco::Net::HTTPResponse::HTTP_OK);
resp.setContentType(contentType);
resp.setContentLength(bufferLen);
std::ostream & out = resp.send();
out.write(reinterpret_cast<const char*>(buffer), bufferLen);
out.flush();
};
示例2: error
void
RemoveByAttributesHandler::handleRequest(Poco::Net::HTTPServerRequest &req, Poco::Net::HTTPServerResponse &resp)
{
prepareApiResponse(resp);
if (req.getMethod() != "POST") {
resp.setStatus(Poco::Net::HTTPResponse::HTTP_BAD_REQUEST);
resp.setReason("Bad Request");
Error error("Only POST requests are supported");
std::ostream & out = resp.send();
out << error;
out.flush();
return;
}
auto job = std::make_shared<Job>(Job::Type::REMOVE_BY_ATTRIBUTES);
try {
// read the whole request body into memory
std::stringstream bodystream;
bodystream << req.stream().rdbuf();
// parse received json into the job object
job->fromString( bodystream.str() );
}
catch (std::exception &e) {
resp.setStatus(Poco::Net::HTTPResponse::HTTP_BAD_REQUEST);
resp.setReason("Bad Request");
Error error(e.what());
poco_warning(logger, e.what());
std::ostream & out = resp.send();
out << error;
out.flush();
return;
}
// return 404 if layer does not exist
try {
auto layer = configuration->getLayer(job->getLayerName());
}
catch (ConfigurationError) {
// layer does not exist
resp.setStatus(Poco::Net::HTTPResponse::HTTP_NOT_FOUND);
resp.setReason("Not Found");
std::stringstream msgstream;
msgstream << "Layer \"" << job->getLayerName() << "\" does not exist";
Error error(msgstream.str());
poco_warning(logger, error.getMessage());
std::ostream & out = resp.send();
out << error;
out.flush();
return;
}
if (auto jobstorage = jobs.lock()) {
poco_debug(logger, "pushing job to jobstorage");
jobstorage->push(job);
}
else {
resp.setStatus(Poco::Net::HTTPResponse::HTTP_INTERNAL_SERVER_ERROR);
resp.setReason("Internal Server Error");
const char * emsg = "Could not get a lock on jobstorage";
Error error(emsg);
poco_error(logger, emsg);
std::ostream & out = resp.send();
out << error;
out.flush();
return;
}
resp.setStatus(Poco::Net::HTTPResponse::HTTP_OK);
std::ostream & out = resp.send();
out << *job;
out.flush();
};