本文整理汇总了C++中poco::net::HTTPServerResponse类的典型用法代码示例。如果您正苦于以下问题:C++ HTTPServerResponse类的具体用法?C++ HTTPServerResponse怎么用?C++ HTTPServerResponse使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HTTPServerResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: handle
void RedirectRequestHandler::handle(Poco::Net::HTTPServerRequest & request, Poco::Net::HTTPServerResponse & response){
response.set("Location", to);
response.setStatusAndReason(Poco::Net::HTTPServerResponse::HTTP_SEE_OTHER);
response.setContentLength(0);
response.send();
}
示例2: handleRequest
void FileSystemRouteHandler::handleRequest(Poco::Net::HTTPServerRequest& request,
Poco::Net::HTTPServerResponse& response)
{
Poco::Path dataFolder(ofToDataPath("",true));
Poco::Path documentRoot(ofToDataPath(_parent.getSettings().getDocumentRoot(),true));
std::string dataFolderString = dataFolder.toString();
std::string documentRootString = documentRoot.toString();
// doc root validity check
if(_parent.getSettings().getRequireDocumentRootInDataFolder() &&
(documentRootString.length() < dataFolderString.length() ||
documentRootString.substr(0,dataFolderString.length()) != dataFolderString))
{
ofLogError("ServerDefaultRouteHandler::handleRequest") << "Document Root is not a sub directory of the data folder.";
response.setStatusAndReason(Poco::Net::HTTPResponse::HTTP_INTERNAL_SERVER_ERROR);
_parent.handleRequest(request,response);
return;
}
// check path
Poco::URI uri(request.getURI());
std::string path = uri.getPath(); // just get the path
// make paths absolute
if(path.empty())
{
path = "/";
}
Poco::Path requestPath = documentRoot.append(path).makeAbsolute();
// add the default index if no filename is requested
if(requestPath.getFileName().empty())
{
requestPath.append(_parent.getSettings().getDefaultIndex()).makeAbsolute();
}
std::string requestPathString = requestPath.toString();
// double check path safety (not needed?)
if((requestPathString.length() < documentRootString.length() ||
requestPathString.substr(0,documentRootString.length()) != documentRootString))
{
ofLogError("ServerDefaultRouteHandler::handleRequest") << "Requested document not inside DocumentFolder.";
response.setStatusAndReason(Poco::Net::HTTPResponse::HTTP_NOT_FOUND);
_parent.handleRequest(request,response);
return;
}
ofFile file(requestPathString); // use it to parse file name parts
try
{
// ofx::Media::MediaTypeMap mediaMap;
// Poco::Net::MediaType mediaType = mediaMap.getMediaTypeForSuffix(file.getExtension());
std::string mediaTypeString = "application/octet-stream";
std::string ext = file.getExtension();
if(ext == "json")
{
mediaTypeString = "application/json";
}
else if(ext == "html")
{
mediaTypeString = "text/html";
}
else if(ext == "jpg" || ext == "jpeg")
{
mediaTypeString = "image/jpeg";
}
else if(ext == "png")
{
mediaTypeString = "image/png";
}
else if(ext == "js")
{
mediaTypeString = "application/javascript";
}
else if(ext == "css")
{
mediaTypeString = "text/css";
}
else if(ext == "xml")
{
mediaTypeString = "application/xml";
}
else if(ext == "ico")
{
mediaTypeString = "image/x-icon";
}
response.sendFile(file.getAbsolutePath(), mediaTypeString); // will throw exceptions
return;
}
catch (const Poco::FileNotFoundException& ex)
{
//.........这里部分代码省略.........
示例3: 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");
}
}
}
示例4: handleRequest
void handleRequest(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response)
{
//Poco::Util::Application& app = Poco::Util::Application::instance();
//app.logger().information("Request from " + request.clientAddress().toString());
std::cout << "Request from " << request.clientAddress().toString() << std::endl;
MyPartHandler partHandler;
Poco::Net::HTMLForm form(request, request.stream(), partHandler);
std::string spinToken, sceneString, nodeString, args;
std::istringstream pathstream(request.getURI());
pathstream.get(); // ignore leading slash
getline(pathstream, spinToken, '/');
getline(pathstream, sceneString, '/');
getline(pathstream, nodeString, '?');
if (sceneString.empty()) sceneString = "default";
//if (nodeString.empty()) nodeString = "shp";
if (form.empty()) args = "createNode shp ShapeNode";
else args = form["args"];
response.setChunkedTransferEncoding(true);
response.setContentType("text/html");
std::ostream& ostr = response.send();
ostr <<
"<html>\n"
"<head>\n"
"<title>SPIN Web Service</title>\n"
"</head>\n"
"<body>\n"
"<h1>SPIN Web Service</h1>\n"
"<h3>Enter a SPIN command in the form below:</h3>\n"
"<table><tr><td nowrap=\"nowrap\">\n"
"<form name=\"urlForm\" method=\"GET\" action=\"null\">\n"
"/SPIN/"
"<input type=\"text\" name=\"sceneID\" value=\"" << sceneString << "\" size=\"10\">\n"
"/<input type=\"text\" name=\"nodeID\" value=\"" << nodeString << "\" size=\"10\">"
"</form></td>\n"
"<td nowrap=\"nowrap\">\n"
"<form name=\"spinform\" method=\"GET\" action=\"null\">\n"
"<input type=\"text\" name=\"args\" value=\"" << args << "\" size=\"20\">\n"
"<input type=\"submit\" value=\"GO\" onclick=\"this.form.action='/SPIN/'+document.forms['urlForm']['sceneID'].value+'/'+document.forms['urlForm']['nodeID'].value\">\n"
"</form>\n"
"</tr></table>\n"
"<p>(NOTE: you can send scene messages by leaving the node name blank)</p>\n"
"\n";
/*
ostr <<
"<html>\n"
"<head>\n"
"<title>SPIN Web Server Sample</title>\n"
"</head>\n"
"<body>\n"
"<h1>SPIN Web Server Sample</h1>\n"
"<h2>Tests:</h2>\n"
"<form name=\"spinform\" method=\"GET\" action=\"null\">\n"
"/SPIN/default/"
"<input type=\"text\" name=\"nodeID\" value=\"shp\" size=\"15\">"
" "
"<input type=\"text\" name=\"method\" value=\"rotate\" size=\"15\">"
" move<input type=\"text\" name=\"x\" value=\"0\" size=\"3\">"
" <input type=\"text\" name=\"y\" value=\"0\" size=\"3\">"
" <input type=\"text\" name=\"z\" value=\"10\" size=\"3\">\n"
" <input type=\"submit\" value=\"GO\" onclick=\"this.form.action='/SPIN/default/'+this.form.nodeID.value\">\n"
"</form>\n"
"\n";
ostr <<
"<html>\n"
"<head>\n"
"<title>SPIN Web Server Sample</title>\n"
"</head>\n"
"<body>\n"
"<h1>SPIN Web Server Sample</h1>\n"
"<h2>GET Form</h2>\n"
"<form method=\"GET\" action=\"/form\">\n"
"<input type=\"text\" name=\"text\" size=\"31\">\n"
"<input type=\"submit\" value=\"GET\">\n"
"</form>\n"
"<h2>POST Form</h2>\n"
"<form method=\"POST\" action=\"/form\">\n"
"<input type=\"text\" name=\"text\" size=\"31\">\n"
"<input type=\"submit\" value=\"POST\">\n"
"</form>\n"
"<h2>File Upload</h2>\n"
"<form method=\"POST\" action=\"/form\" enctype=\"multipart/form-data\">\n"
"<input type=\"file\" name=\"file\" size=\"31\"> \n"
"<input type=\"submit\" value=\"Upload\">\n"
"</form>\n";
*/
ostr << "<h2>Result</h2><p>\n";
ostr << "Method: " << request.getMethod() << "<br>\n";
ostr << "URI: " << request.getURI() << "<br>\n";
Poco::Net::NameValueCollection::ConstIterator it = request.begin();
Poco::Net::NameValueCollection::ConstIterator end = request.end();
for (; it != end; ++it)
{
ostr << it->first << ": " << it->second << "<br>\n";
//.........这里部分代码省略.........
示例5: handleRequest
void ControllerRequestHandler::handleRequest(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response)
{
if (request.getURI() == "/favicon.ico")
{
return response.redirect("/images/favicon.ico", Poco::Net::HTTPResponse::HTTP_SEE_OTHER);
}
Poco::OSP::Web::WebSession::Ptr pSession = _pSessionManager->get(_sessionId, request, _sessionTimeout, context());
const std::string loginPage = "/macchina/login";
const std::string launcherPage = "/macchina/launcher";
std::string message;
std::string nextPage;
std::string username;
Poco::Net::HTMLForm form(request, request.stream());
std::string action(form.get("action", ""));
if (action == "login")
{
username = form.get("username", "");
std::string password = form.get("password", "");
if (_pAuthService->authenticate(username, password))
{
if (_logger.information())
{
_logger.information(format("User %s successfully logged in.", username));
}
nextPage = launcherPage;
pSession->set("username", username);
}
else
{
if (_logger.warning())
{
_logger.warning(format("User %s failed authentication.", username));
}
message = "The given username is not known, the password is wrong or the account has been disabled.";
}
}
else if (action == "logout")
{
username = pSession->getValue<std::string>("username", "");
if (!username.empty())
{
if (_logger.information())
{
_logger.information(format("User %s logged out.", username));
}
_pSessionManager->remove(pSession);
}
}
else
{
username = pSession->getValue<std::string>("username", "");
if (!username.empty())
{
nextPage = launcherPage;
}
}
if (!message.empty())
{
pSession->set("message", message);
}
else
{
pSession->erase("message");
}
if (nextPage.empty())
{
nextPage = loginPage;
}
response.setContentLength(0);
response.redirect(nextPage, Poco::Net::HTTPResponse::HTTP_SEE_OTHER);
response.set("Cache-Control", "no-cache");
}
示例6: error_parse
void RESTHandler::error_parse(Poco::Net::HTTPServerResponse &response) {
response.setStatusAndReason(Poco::Net::HTTPServerResponse::HTTP_BAD_REQUEST, "Parse failed");
response.send() << "Invalid JSON arguments" << std::flush;
}
示例7: handleRequest
void AppRequestHandler::handleRequest(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response)
{
// Check for the favicon.ico request, we don't have one for now,
// so set status code to HTTP_NOT_FOUND
if ( request.getURI().compare("/favicon.ico") == 0 )
{
response.setStatus(Poco::Net::HTTPResponse::HTTP_NOT_FOUND);
response.send();
return;
}
std::string lastModifiedHeader = request.get("If-Modified-Since", "");
Poco::URI uri(request.getURI());
Poco::Util::Application& app = Poco::Util::Application::instance();
std::string staticPathname = app.config().getString("mq.web.app", "");
if ( staticPathname.empty() )
{
Poco::Logger& logger = Poco::Logger::get("mq.web");
logger.error("mq.web.app property not defined. Check your configuration.");
response.setStatus(Poco::Net::HTTPResponse::HTTP_INTERNAL_SERVER_ERROR);
response.send();
return;
}
Poco::Path staticPath(staticPathname);
staticPath.makeDirectory();
std::vector<std::string> uriPathSegments;
uri.getPathSegments(uriPathSegments);
std::vector<std::string>::iterator it = uriPathSegments.begin();
it++;
for(; it != uriPathSegments.end(); ++it)
{
staticPath.append(*it);
}
if (staticPath.isDirectory())
{
staticPath.append("index.html");
}
Poco::File staticFile(staticPath);
Poco::Logger& logger = Poco::Logger::get("mq.web.access");
if ( staticFile.exists() )
{
if ( !lastModifiedHeader.empty() )
{
Poco::DateTime lastModifiedDate;
int timeZoneDifferential = 0;
if ( Poco::DateTimeParser::tryParse(Poco::DateTimeFormat::HTTP_FORMAT, lastModifiedHeader, lastModifiedDate, timeZoneDifferential) )
{
if ( staticFile.getLastModified() <= lastModifiedDate.timestamp() )
{
logger.information(Poco::Logger::format("$0 : HTTP_NOT_MODIFIED", staticPath.toString()));
response.setStatus(Poco::Net::HTTPResponse::HTTP_NOT_MODIFIED);
response.send();
return;
}
}
}
logger.information(Poco::Logger::format("$0 : HTTP_OK", staticPath.toString()));
std::string mimeType;
if ( staticPath.getExtension().compare("gif") == 0 )
{
mimeType = "image/gif";
}
else if ( staticPath.getExtension().compare("css") == 0 )
{
mimeType = "text/css";
}
else if ( staticPath.getExtension().compare("html") == 0 || staticPath.getExtension().compare("htm") == 0)
{
mimeType = "text/html";
}
else if ( staticPath.getExtension().compare("js") == 0 )
{
mimeType = "text/javascript";
}
else if ( staticPath.getExtension().compare("png") == 0 )
{
mimeType = "image/png";
}
else if ( staticPath.getExtension().compare("jpg") == 0 || staticPath.getExtension().compare("jpeg") == 0)
{
mimeType = "image/jpeg";
}
try
{
response.sendFile(staticPath.toString(), mimeType);
}
catch(Poco::FileNotFoundException&)
{
// We can't get here normally ... but you never know :)
response.setStatusAndReason(Poco::Net::HTTPResponse::HTTP_NOT_FOUND, Poco::Logger::format("Can't find file $0", staticPath.toString()));
}
//.........这里部分代码省略.........
示例8: 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();
};
示例9: handleRequest
void RegistrationHandler::handleRequest(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response)
{
response.setChunkedTransferEncoding(true);
response.setContentType("text/html");
#line 6 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/Registration.c"
SESSION std::ostream& responseStream = response.send();
responseStream << "";
responseStream << "\n";
responseStream << "";
responseStream << "\n";
responseStream << "";
responseStream << "\n";
responseStream << "";
responseStream << "\n";
responseStream << "\n";
responseStream << "\t";
responseStream << "\n";
responseStream << "\n";
responseStream << "\t";
#line 8 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/Registration.c"
TILE_BEGIN("head") responseStream << "";
// begin include src/view/tile/head.html
responseStream << "\n";
responseStream << "\t<meta charset=\"utf-8\">\n";
responseStream << "\t<meta http-equiv=\"X-UA-Compatible\" content=\"IE=9\" />\n";
responseStream << "\t<script type=\"text/javascript\">window.suggestmeyes_loaded = true;</script>\n";
responseStream << "\t<title>Main Page</title>\n";
responseStream << "\t<link rel=\"stylesheet\" type=\"text/css\" href=\"css/style.css\">\n";
responseStream << "\t<!--<meta http-equiv=\"refresh\" content=\"1\">-->\n";
responseStream << "";
// end include src/view/tile/head.html
responseStream << "";
#line 8 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/Registration.c"
TILE_END responseStream << "\n";
responseStream << "\t";
#line 9 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/Registration.c"
TILE_BEGIN("topbar") responseStream << "";
// begin include src/view/tile/topbar.html
responseStream << "\n";
responseStream << "\t";
#line 2 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/tile/topbar.html"
IF(user) responseStream << "\n";
responseStream << "\t\t<div id=\"session\">\n";
responseStream << "\t\t\t<span class=\"topbar\">\n";
responseStream << "\t\t\t\t<a class=\"topbar\" href=\"/User\"><span class=\"topbar\">\n";
responseStream << "\t\t\t\t\t";
#line 6 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/tile/topbar.html"
IF(user.group() == user.ADMIN) responseStream << "#";
#line 6 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/tile/topbar.html"
responseStream << (user.username());
responseStream << "#";
#line 6 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/tile/topbar.html"
ELSE responseStream << "[";
#line 6 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/tile/topbar.html"
responseStream << (user.username());
responseStream << "]";
#line 6 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/tile/topbar.html"
ENDIF responseStream << "\n";
responseStream << "\t\t\t\t</span></a>\n";
responseStream << "\t\t\t\t<a class=\"topbar\" href=\"/*logout\">Sign out</a>\n";
responseStream << "\t\t\t</span>\n";
responseStream << "\t\t</div>\n";
responseStream << "\t";
#line 11 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/tile/topbar.html"
ELSE responseStream << "\n";
responseStream << "\t\t<script type=\"text/javascript\"> function submitSigninForm() { document.forms[\"signinForm\"].submit(); } </script>\n";
responseStream << "\t\t<form id=\"signinForm\" class=\"ignore\" method=\"POST\" action=\"*login\">";
#line 13 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/tile/topbar.html"
responseStream << (CSRF);
responseStream << "\n";
responseStream << "\t\t\t<div id=\"session\">\n";
responseStream << "\t\t\t\t<span class=\"topbar\">\n";
responseStream << "\t\t\t\t\t<input class=\"topbar\" type=\"text\" ";
#line 16 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/tile/topbar.html"
responseStream << (NAME(username));
responseStream << " placeholder=\"Username...\" style=\"width: 100px;\" onkeypress=\"if(event.keyCode==13) submitSigninForm();\">\n";
responseStream << "\t\t\t\t\t<input class=\"topbar\" type=\"password\" ";
#line 17 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/tile/topbar.html"
responseStream << (NAME(password));
responseStream << " placeholder=\"Password...\" style=\"width: 100px;\" onkeypress=\"if(event.keyCode==13) submitSigninForm();\">\n";
responseStream << "\t\t\t\t\t<!--<a class=\"topbar\" href=\"/Login\">Sign In</a>-->\n";
responseStream << "\t\t\t\t\t<a class=\"topbar\" href=\"javascript:submitSigninForm()\">Log in</a>\n";
responseStream << "\t\t\t\t\t<a class=\"topbar\" href=\"/Registration\">Sign up</a>\n";
responseStream << "\t\t\t\t</span>\n";
responseStream << "\t\t\t</div>\n";
responseStream << "\t\t</form>\n";
responseStream << "\t";
#line 24 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/tile/topbar.html"
ENDIF responseStream << "\n";
responseStream << "";
// end include src/view/tile/topbar.html
responseStream << "";
#line 9 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/Registration.c"
TILE_END responseStream << "\n";
responseStream << "\t";
#line 10 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/Registration.c"
TILE_BEGIN("header") responseStream << "";
// begin include src/view/tile/header.html
responseStream << "\n";
//.........这里部分代码省略.........
示例10:
void
Handler::prepareResponse(Poco::Net::HTTPServerResponse &resp)
{
resp.set("Server", APP_NAME_SERVER_FULL);
}
示例11: handleRequest
void BlogHandler::handleRequest(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response)
{
response.setChunkedTransferEncoding(true);
response.setContentType("text/html");
#line 6 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/Blog.c"
SESSION std::ostream& responseStream = response.send();
responseStream << "";
responseStream << "\n";
responseStream << "";
responseStream << "\n";
responseStream << "";
responseStream << "\n";
responseStream << "";
responseStream << "\n";
responseStream << "\n";
responseStream << "\t";
responseStream << "\n";
responseStream << "\n";
responseStream << "\t";
#line 8 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/Blog.c"
TILE_BEGIN("head") responseStream << "\n";
responseStream << "\t\t";
// begin include src/view/tile/head.html
responseStream << "\n";
responseStream << "\t<meta charset=\"utf-8\">\n";
responseStream << "\t<meta http-equiv=\"X-UA-Compatible\" content=\"IE=9\" />\n";
responseStream << "\t<script type=\"text/javascript\">window.suggestmeyes_loaded = true;</script>\n";
responseStream << "\t<title>Main Page</title>\n";
responseStream << "\t<link rel=\"stylesheet\" type=\"text/css\" href=\"css/style.css\">\n";
responseStream << "\t<!--<meta http-equiv=\"refresh\" content=\"1\">-->\n";
responseStream << "";
// end include src/view/tile/head.html
responseStream << "\n";
responseStream << "\t\t<link rel=\"stylesheet\" type=\"text/css\" href=\"markitup/skins/markitup/style.css\" />\n";
responseStream << "\t\t<link rel=\"stylesheet\" type=\"text/css\" href=\"markitup/sets/bbcode/style.css\" />\n";
responseStream << "\t\t<script type=\"text/javascript\" src=\"js/jquery-1.4.3.min.js\"></script>\n";
responseStream << "\t\t<script type=\"text/javascript\" src=\"markitup/jquery.markitup.js\"></script>\n";
responseStream << "\t\t<script type=\"text/javascript\" src=\"markitup/sets/bbcode/set.js\"></script>\n";
responseStream << "\t\t<script language=\"javascript\">\n";
responseStream << "\t\t$(document).ready(function()\t{\n";
responseStream << "\t\t\t$('#bbcode_blog').markItUp(myBbcodeSettings);\n";
responseStream << "\t\t\t$('#emoticons a').click(function() {\n";
responseStream << "\t\t\t\temoticon = $(this).attr(\"title\");\n";
responseStream << "\t\t\t\t$.markItUp( { replaceWith:emoticon } );\n";
responseStream << "\t\t\t});\n";
responseStream << "\t\t});\n";
responseStream << "\t\t</script>\n";
responseStream << "\t";
#line 24 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/Blog.c"
TILE_END responseStream << "\n";
responseStream << "\n";
responseStream << "\t";
#line 26 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/Blog.c"
TILE_BEGIN("topbar") responseStream << "";
// begin include src/view/tile/topbar.html
responseStream << "\n";
responseStream << "\t";
#line 2 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/tile/topbar.html"
IF(user) responseStream << "\n";
responseStream << "\t\t<div id=\"session\">\n";
responseStream << "\t\t\t<span class=\"topbar\">\n";
responseStream << "\t\t\t\t<a class=\"topbar\" href=\"/User\"><span class=\"topbar\">\n";
responseStream << "\t\t\t\t\t";
#line 6 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/tile/topbar.html"
IF(user.group() == user.ADMIN) responseStream << "#";
#line 6 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/tile/topbar.html"
responseStream << (user.username());
responseStream << "#";
#line 6 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/tile/topbar.html"
ELSE responseStream << "[";
#line 6 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/tile/topbar.html"
responseStream << (user.username());
responseStream << "]";
#line 6 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/tile/topbar.html"
ENDIF responseStream << "\n";
responseStream << "\t\t\t\t</span></a>\n";
responseStream << "\t\t\t\t<a class=\"topbar\" href=\"/*logout\">Sign out</a>\n";
responseStream << "\t\t\t</span>\n";
responseStream << "\t\t</div>\n";
responseStream << "\t";
#line 11 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/tile/topbar.html"
ELSE responseStream << "\n";
responseStream << "\t\t<script type=\"text/javascript\"> function submitSigninForm() { document.forms[\"signinForm\"].submit(); } </script>\n";
responseStream << "\t\t<form id=\"signinForm\" class=\"ignore\" method=\"POST\" action=\"*login\">";
#line 13 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/tile/topbar.html"
responseStream << (CSRF);
responseStream << "\n";
responseStream << "\t\t\t<div id=\"session\">\n";
responseStream << "\t\t\t\t<span class=\"topbar\">\n";
responseStream << "\t\t\t\t\t<input class=\"topbar\" type=\"text\" ";
#line 16 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/tile/topbar.html"
responseStream << (NAME(username));
responseStream << " placeholder=\"Username...\" style=\"width: 100px;\" onkeypress=\"if(event.keyCode==13) submitSigninForm();\">\n";
responseStream << "\t\t\t\t\t<input class=\"topbar\" type=\"password\" ";
#line 17 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/tile/topbar.html"
responseStream << (NAME(password));
responseStream << " placeholder=\"Password...\" style=\"width: 100px;\" onkeypress=\"if(event.keyCode==13) submitSigninForm();\">\n";
responseStream << "\t\t\t\t\t<!--<a class=\"topbar\" href=\"/Login\">Sign In</a>-->\n";
responseStream << "\t\t\t\t\t<a class=\"topbar\" href=\"javascript:submitSigninForm()\">Log in</a>\n";
//.........这里部分代码省略.........
示例12: handleRequest
void FileSystemRouteHandler::handleRequest(Poco::Net::HTTPServerRequest& request,
Poco::Net::HTTPServerResponse& response)
{
Poco::Path dataFolder(ofToDataPath("", true));
Poco::Path documentRoot(ofToDataPath(_parent.getSettings().getDocumentRoot(), true));
std::string dataFolderString = dataFolder.toString();
std::string documentRootString = documentRoot.toString();
// doc root validity check
if(_parent.getSettings().getRequireDocumentRootInDataFolder() &&
(documentRootString.length() < dataFolderString.length() ||
documentRootString.substr(0,dataFolderString.length()) != dataFolderString))
{
ofLogError("ServerDefaultRouteHandler::handleRequest") << "Document Root is not a sub directory of the data folder.";
response.setStatusAndReason(Poco::Net::HTTPResponse::HTTP_INTERNAL_SERVER_ERROR);
_parent.handleRequest(request,response);
return;
}
// check path
Poco::URI uri(request.getURI());
std::string path = uri.getPath(); // just get the path
// make paths absolute
if(path.empty())
{
path = "/";
}
Poco::Path requestPath = documentRoot.append(path).makeAbsolute();
// add the default index if no filename is requested
if(requestPath.getFileName().empty())
{
requestPath.append(_parent.getSettings().getDefaultIndex()).makeAbsolute();
}
std::string requestPathString = requestPath.toString();
// double check path safety (not needed?)
if((requestPathString.length() < documentRootString.length() ||
requestPathString.substr(0,documentRootString.length()) != documentRootString))
{
ofLogError("ServerDefaultRouteHandler::handleRequest") << "Requested document not inside DocumentFolder.";
response.setStatusAndReason(Poco::Net::HTTPResponse::HTTP_NOT_FOUND);
_parent.handleRequest(request,response);
return;
}
ofFile file(requestPathString); // use it to parse file name parts
std::string mediaTypeString = Media::MediaTypeMap::getDefault()->getMediaTypeForPath(file.path()).toString();
try
{
// TODO: this is where we would begin to work honoring
/// Accept-Encoding:gzip, deflate, sdch
response.sendFile(file.getAbsolutePath(), mediaTypeString);
return;
}
catch (const Poco::FileNotFoundException& ex)
{
ofLogError("ServerDefaultRouteHandler::handleRequest") << ex.displayText();
response.setStatusAndReason(Poco::Net::HTTPResponse::HTTP_NOT_FOUND);
_parent.handleRequest(request,response);
}
catch (const Poco::OpenFileException& ex)
{
ofLogError("ServerDefaultRouteHandler::handleRequest") << ex.displayText();
response.setStatusAndReason(Poco::Net::HTTPResponse::HTTP_INTERNAL_SERVER_ERROR);
_parent.handleRequest(request,response);
}
catch (const exception& ex)
{
ofLogError("ServerDefaultRouteHandler::handleRequest") << "Unknown server error: " << ex.what();
response.setStatusAndReason(Poco::Net::HTTPResponse::HTTP_INTERNAL_SERVER_ERROR);
_parent.handleRequest(request,response);
}
}
示例13: handleRequest
void ODBCHandler::handleRequest(Poco::Net::HTTPServerRequest & request, Poco::Net::HTTPServerResponse & response)
{
Poco::Net::HTMLForm params(request, request.stream());
LOG_TRACE(log, "Request URI: " + request.getURI());
auto process_error = [&response, this](const std::string & message)
{
response.setStatusAndReason(Poco::Net::HTTPResponse::HTTP_INTERNAL_SERVER_ERROR);
if (!response.sent())
response.send() << message << std::endl;
LOG_WARNING(log, message);
};
if (!params.has("query"))
{
process_error("No 'query' in request body");
return;
}
if (!params.has("columns"))
{
process_error("No 'columns' in request URL");
return;
}
if (!params.has("connection_string"))
{
process_error("No 'connection_string' in request URL");
return;
}
UInt64 max_block_size = DEFAULT_BLOCK_SIZE;
if (params.has("max_block_size"))
{
std::string max_block_size_str = params.get("max_block_size", "");
if (max_block_size_str.empty())
{
process_error("Empty max_block_size specified");
return;
}
max_block_size = parse<size_t>(max_block_size_str);
}
std::string columns = params.get("columns");
std::unique_ptr<Block> sample_block;
try
{
sample_block = parseColumns(std::move(columns));
}
catch (const Exception & ex)
{
process_error("Invalid 'columns' parameter in request body '" + ex.message() + "'");
LOG_WARNING(log, ex.getStackTrace().toString());
return;
}
std::string format = params.get("format", "RowBinary");
std::string query = params.get("query");
LOG_TRACE(log, "Query: " << query);
std::string connection_string = params.get("connection_string");
LOG_TRACE(log, "Connection string: '" << connection_string << "'");
WriteBufferFromHTTPServerResponse out(request, response, keep_alive_timeout);
try
{
BlockOutputStreamPtr writer = FormatFactory::instance().getOutput(format, out, *sample_block, *context);
auto pool = getPool(connection_string);
ODBCBlockInputStream inp(pool->get(), query, *sample_block, max_block_size);
copyData(inp, *writer);
}
catch (...)
{
auto message = getCurrentExceptionMessage(true);
response.setStatusAndReason(
Poco::Net::HTTPResponse::HTTP_INTERNAL_SERVER_ERROR); // can't call process_error, bacause of too soon response sending
writeStringBinary(message, out);
tryLogCurrentException(log);
}
}
示例14: error_timeout
void RESTHandler::error_timeout(Poco::Net::HTTPServerResponse &response) {
response.setStatusAndReason(Poco::Net::HTTPServerResponse::HTTP_REQUEST_TIMEOUT, "External system timeout");
response.send() << "External system request timeout" << std::flush;
}
示例15: handleRequest
void ShowFilePage::handleRequest(Poco::Net::HTTPServerRequest &request, Poco::Net::HTTPServerResponse &response)
{
m_log->trace("ShowFilePage::handleRequest from "+request.clientAddress().toString());
m_log->trace("ShowFilePage::handleRequest ContentType="+request.getContentType());
m_log->trace("ShowFilePage::handleRequest TransferEncoding="+request.getTransferEncoding());
m_log->trace("ShowFilePage::handleRequest URI="+request.getURI());
std::map<std::string,QueryVar> queryvars;
CreateQueryVarMap(request,queryvars);
std::string content="";
if(queryvars.find("file")!=queryvars.end() && m_filewhitelist.find((*queryvars.find("file")).second.GetData())!=m_filewhitelist.end())
{
try
{
response.sendFile(global::basepath+(*queryvars.find("file")).second.GetData(),m_filewhitelist[(*queryvars.find("file")).second.GetData()]);
}
catch(Poco::FileNotFoundException &fnf)
{
m_log->error("ShowFilePage::handleRequest caught FileNotFound exception - "+fnf.message());
}
catch(Poco::OpenFileException &of)
{
m_log->error("ShowFilePage::handleRequest caught OpenFile exception - "+of.message());
}
catch(...)
{
m_log->error("ShowFilePage::handleRequest caught other exception");
}
}
else if(request.getURI().size()>0 && request.getURI()[0]=='/' && m_filewhitelist.find(request.getURI().substr(1))!=m_filewhitelist.end())
{
try
{
response.sendFile(global::basepath+request.getURI().substr(1),m_filewhitelist[request.getURI().substr(1)]);
}
catch(Poco::FileNotFoundException &fnf)
{
m_log->error("ShowFilePage::handleRequest caught FileNotFound exception - "+fnf.message());
}
catch(Poco::OpenFileException &of)
{
m_log->error("ShowFilePage::handleRequest caught OpenFile exception - "+of.message());
}
catch(...)
{
m_log->error("ShowFilePage::handleRequest caught other exception");
}
}
else if(request.getURI().size()>0 && m_filewhitelist.find(request.getURI())!=m_filewhitelist.end())
{
try
{
response.sendFile(global::basepath+request.getURI(),m_filewhitelist[request.getURI()]);
}
catch(Poco::FileNotFoundException &fnf)
{
m_log->error("ShowFilePage::handleRequest caught FileNotFound exception - "+fnf.message());
}
catch(Poco::OpenFileException &of)
{
m_log->error("ShowFilePage::handleRequest caught OpenFile exception - "+of.message());
}
catch(...)
{
m_log->error("ShowFilePage::handleRequest caught other exception");
}
}
}