本文整理汇总了C++中HTTPServerRequest::clientAddress方法的典型用法代码示例。如果您正苦于以下问题:C++ HTTPServerRequest::clientAddress方法的具体用法?C++ HTTPServerRequest::clientAddress怎么用?C++ HTTPServerRequest::clientAddress使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HTTPServerRequest
的用法示例。
在下文中一共展示了HTTPServerRequest::clientAddress方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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};
}
示例2: 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>";
}
示例3: handleRequest
void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response)
{
Application& app = Application::instance();
app.logger().information("Request from " + request.clientAddress().toString());
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>";
}
示例4: handleRequest
void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response)
{
HTMLForm form(request, request.stream());
response.setContentType("text/html");
response.setChunkedTransferEncoding(true);
std::ostream& ostr = response.send();
URI requestURI(request.getURI());
ostr << "<html><head><title>Echo HTTP Headers and HTML Form 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\">Echo HTTP Headers and HTML Form Information</H1>"
"</div>"
"<div class=\"body\">";
// echo the items available by method
ostr << "<h2>Request</h2>"
<< "<ul>"
<< "<li><b>Method:</b> " << request.getMethod() << "</li>"
<< "<li><b>URI Path:</b> " << requestURI.getPath() << "</li>"
<< "<li><b>URI Query:</b> " << requestURI.getQuery() << "</li>"
<< "<li><b>HTTP Version:</b> " << request.getVersion() << "</li>"
<< "<li><b>Host:</b> " << request.getHost() << "</li>"
<< "<li><b>Content Type:</b> " << request.getContentType() << "</li>"
<< "<li><b>Chunked:</b> " << (request.getChunkedTransferEncoding() ? "true" : "false") << "</li>"
<< "<li><b>Keep Alive:</b> " << (request.getKeepAlive() ? "true" : "false") << "</li>"
<< "<li><b>Transfer Encoding:</b> " << request.getTransferEncoding() << "</li>"
<< "<li><b>Client Address:</b> " << request.clientAddress().toString() << "</li>";
if (request.hasContentLength())
{
ostr << "<li><b>Content Length:</b> " << request.getContentLength64() << "</li>";
}
ostr << "</ul>";
// echo the request headers
{
ostr << "<hr>"
"<h2>Request Headers</h2><ul>\n";
NameValueCollection headers;
NameValueCollection::ConstIterator itr(request.begin());
NameValueCollection::ConstIterator itrEnd(request.end());
for (; itr != itrEnd; ++itr)
{
ostr << "<li><b>" << htmlize(itr->first) << "</b>: " << htmlize(itr->second) << "</li>";
}
ostr << "</ul>";
}
// echo any cookies
{
NameValueCollection cookies;
request.getCookies(cookies);
if (!cookies.empty())
{
ostr << "<hr>";
ostr << "<h2>Cookies</h2><ul>\n";
NameValueCollection::ConstIterator itr(cookies.begin());
NameValueCollection::ConstIterator itrEnd(cookies.end());
for (; itr != itrEnd; ++itr)
{
ostr << "<li><b>" << htmlize(itr->first) << "</b>: " << htmlize(itr->second) << "</li>";
}
ostr << "</ul>";
}
}
// echo any form data (GETs or POSTs)
if (!form.empty())
{
ostr << "<hr>"
"<h2>Form Data</h2><ul>\n";
NameValueCollection::ConstIterator itr(form.begin());
NameValueCollection::ConstIterator itrEnd(form.end());
for (; itr != itrEnd; ++itr)
{
ostr << "<li><b>" << htmlize(itr->first) << "</b>: " << htmlize(itr->second) << "</li>\n";
}
ostr << "</ul>";
}
ostr << "<hr>"
<< "<h2>Response</h2>"
<< "<ul>"
<< "<li><b>Status:</b> " << response.getStatus() << "</li>"
<< "<li><b>Reason:</b> " << response.getReason() << "</li>"
<< "</ul>";
// echo the response headers
//.........这里部分代码省略.........
示例5: handleRequest
void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response)
{
Application& app = Application::instance();
app.logger().information("Request from " + request.clientAddress().toString());
MyPartHandler partHandler;
HTMLForm form(request, request.stream(), partHandler);
response.setChunkedTransferEncoding(true);
response.setContentType("text/html");
std::ostream& ostr = response.send();
ostr <<
"<html>\n"
"<head>\n"
"<title>POCO Form Server Sample</title>\n"
"</head>\n"
"<body>\n"
"<h1>POCO Form 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>Request</h2><p>\n";
ostr << "Method: " << request.getMethod() << "<br>\n";
ostr << "URI: " << request.getURI() << "<br>\n";
NameValueCollection::ConstIterator it = request.begin();
NameValueCollection::ConstIterator end = request.end();
for (; it != end; ++it)
{
ostr << it->first << ": " << it->second << "<br>\n";
}
ostr << "</p>";
if (!form.empty())
{
ostr << "<h2>Form</h2><p>\n";
it = form.begin();
end = form.end();
for (; it != end; ++it)
{
ostr << it->first << ": " << it->second << "<br>\n";
}
ostr << "</p>";
}
if (!partHandler.name().empty())
{
ostr << "<h2>Upload</h2><p>\n";
ostr << "Name: " << partHandler.name() << "<br>\n";
ostr << "File Name: " << partHandler.fileName() << "<br>\n";
ostr << "Type: " << partHandler.contentType() << "<br>\n";
ostr << "Size: " << partHandler.length() << "<br>\n";
ostr << "</p>";
}
ostr << "</body>\n";
}
示例6: handleRequest
void handleRequest (HTTPServerRequest &request, HTTPServerResponse &response)
{
Application& app = Application::instance();
app.logger().information("Запрос от " + request.clientAddress().toString());
// std::cout << request.getURI() << std::endl;
// std::string filename(request.getURI().substr(0, request.getURI().find("?")));
// app.logger().information("Файл: " + filename);
/*
if (opendir(std::string("www" + filename).c_str()) != NULL)
{
response.setStatus(Poco::Net::HTTPResponse::HTTP_NOT_FOUND);
return;
}
if (filename != "balda.json")
{
ifstream fin(filename.c_str());
if (fin.is_open())
{
}
return;
}
*/
response.setChunkedTransferEncoding(true);
std::ostream &ostr = response.send();
// try
// {
// response.sendFile("/media/hdisk0/programming/project/anbal/2001/www" + filename, "text/plain");
// }
// catch (...)
// {
// ostr << "BAD" << std::endl;
// }
// return;
response.setContentType("text/javascript; charset=UTF-8");
HTMLForm form(request, request.stream());
if (!form.empty())
{
std::map < std::string , Glib::ustring > params;
for (NameValueCollection::ConstIterator it = form.begin(); it != form.end(); ++it)
params[it->first] = Glib::ustring(it->second);
if (params["map"].length() != 25)
return;
std::vector < std::vector < SMyGUniChar > > char_map(5, std::vector < SMyGUniChar >(5));
Glib::ustring u_map = params["map"];
for (int i = 0, len = u_map.length(); i < len; ++i)
char_map[i / 5][i % 5] = SMyGUniChar(u_map[i], i / 5, i % 5, u_map[i] == Glib::ustring(".")[0]);
CBalda balda(*dictionary);
std::vector < Glib::ustring > words = balda.calc(char_map);
ostr << params["callback"] << "({\"word\": [\"" << cat(std::string("\", \""), words.begin(), words.end()) << "\"]})";
}
}
示例7: handleRequest
void DiskInfoRequestHandler::handleRequest(HTTPServerRequest& request,
HTTPServerResponse& response) {
Application& app = Application::instance();
app.logger().information("Start processing request from: "+request.clientAddress().toString());
Timestamp start;
SharedPtr<HDDExplorer> explorer = hddExplorerCache.get(0);
if(explorer.isNull()){
explorer = new HDDExplorer;
hddExplorerCache.add(0, explorer);
}
Object responseObject;
if((*explorer).isSuccessfullyDiscovered() && (*explorer).getAvailableHDDs().size()>0){
responseObject.set("found", true);
vector<string> hdds = (*explorer).getAvailableHDDs();
Array disks;
for(vector<string>::iterator iter = hdds.begin(); iter!=hdds.end(); iter++){
string hddPath = *iter;
SharedPtr<DiskInfo> info = smartInfoCache.get(hddPath);
if(info.isNull()){
info = new DiskInfo(hddPath);
smartInfoCache.add(hddPath, info);
}
Object jsonObject = (*info).toJSONObject();
disks.add(jsonObject);
}
responseObject.set("disks", disks);
} else {
responseObject.set("found", false);
}
response.setContentType("application/javascript; charset=utf-8");
HTMLForm form(request);
string callbackFunc = "callback";
if(form.has("callback") && !form.get("callback").empty()){
callbackFunc = form.get("callback");
}
std::stringstream ostr;
ostr<<callbackFunc<<"("; //send callback for JSONP
responseObject.stringify(ostr);
ostr<<")";
string serialized = ostr.str();
response.sendBuffer(serialized.c_str(), serialized.size());//connection keep-alive. We need to
//know content-length
Timestamp end;
string secs = NumberFormatter::format((end-start)/1000)+" msecs";
app.logger().information("Request from: "+request.clientAddress().toString()+
" succesfully processed in "+secs);
}