summaryrefslogtreecommitdiff
path: root/poco-httpd/poco-httpd.cpp
diff options
context:
space:
mode:
authorTim Redfern <tim@herge.(none)>2013-07-04 10:49:55 +0100
committerTim Redfern <tim@herge.(none)>2013-07-04 10:49:55 +0100
commitfddff1ff3e50260b6518e754714b46e28fefaea6 (patch)
tree3aa94083cde9a5d0086ae3e1365d4c7bcbd0e94d /poco-httpd/poco-httpd.cpp
parent729e602bbf825f909193fd130d68ee9eeafb0eae (diff)
tidying
Diffstat (limited to 'poco-httpd/poco-httpd.cpp')
-rw-r--r--poco-httpd/poco-httpd.cpp169
1 files changed, 0 insertions, 169 deletions
diff --git a/poco-httpd/poco-httpd.cpp b/poco-httpd/poco-httpd.cpp
deleted file mode 100644
index 5ca33b6..0000000
--- a/poco-httpd/poco-httpd.cpp
+++ /dev/null
@@ -1,169 +0,0 @@
-#include "Poco/Net/HTTPServer.h"
-#include "Poco/Net/HTTPRequestHandler.h"
-#include "Poco/Net/HTTPRequestHandlerFactory.h"
-#include "Poco/Net/HTTPServerParams.h"
-#include "Poco/Net/HTTPServerRequest.h"
-#include "Poco/Net/HTTPServerResponse.h"
-#include "Poco/Net/HTTPServerParams.h"
-#include "Poco/Net/ServerSocket.h"
-#include "Poco/Timestamp.h"
-#include "Poco/DateTimeFormatter.h"
-#include "Poco/DateTimeFormat.h"
-#include "Poco/Exception.h"
-#include "Poco/ThreadPool.h"
-#include "Poco/Util/ServerApplication.h"
-#include "Poco/Util/Option.h"
-#include "Poco/Util/OptionSet.h"
-#include "Poco/Util/HelpFormatter.h"
-#include <iostream>
-
-using Poco::Net::ServerSocket;
-using Poco::Net::HTTPRequestHandler;
-using Poco::Net::HTTPRequestHandlerFactory;
-using Poco::Net::HTTPServer;
-using Poco::Net::HTTPServerRequest;
-using Poco::Net::HTTPServerResponse;
-using Poco::Net::HTTPServerParams;
-using Poco::Timestamp;
-using Poco::DateTimeFormatter;
-using Poco::DateTimeFormat;
-using Poco::ThreadPool;
-using Poco::Util::ServerApplication;
-using Poco::Util::Application;
-using Poco::Util::Option;
-using Poco::Util::OptionSet;
-using Poco::Util::OptionCallback;
-using Poco::Util::HelpFormatter;
-
-class TimeRequestHandler: public HTTPRequestHandler
-{
-public:
- TimeRequestHandler(const std::string& format): _format(format)
- {
- }
-
- 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>";
- }
-
-private:
- std::string _format;
-};
-
-class TimeRequestHandlerFactory: public HTTPRequestHandlerFactory
-{
-public:
- TimeRequestHandlerFactory(const std::string& format):
- _format(format)
- {
- }
-
- HTTPRequestHandler* createRequestHandler(
- const HTTPServerRequest& request)
- {
- if (request.getURI() == "/")
- return new TimeRequestHandler(_format);
- else
- return 0;
- }
-
-private:
- std::string _format;
-};
-
-class HTTPTimeServer: public Poco::Util::ServerApplication
-{
-public:
- HTTPTimeServer(): _helpRequested(false)
- {
- }
-
- ~HTTPTimeServer()
- {
- }
-
-protected:
- void initialize(Application& self)
- {
- loadConfiguration();
- ServerApplication::initialize(self);
- }
-
- void uninitialize()
- {
- ServerApplication::uninitialize();
- }
-
- void defineOptions(OptionSet& options)
- {
- ServerApplication::defineOptions(options);
-
- options.addOption(
- Option("help", "h", "display argument help information")
- .required(false)
- .repeatable(false)
- .callback(OptionCallback<HTTPTimeServer>(
- this, &HTTPTimeServer::handleHelp)));
- }
-
- void handleHelp(const std::string& name,
- const std::string& value)
- {
- HelpFormatter helpFormatter(options());
- helpFormatter.setCommand(commandName());
- helpFormatter.setUsage("OPTIONS");
- helpFormatter.setHeader(
- "A web server that serves the current date and time.");
- helpFormatter.format(std::cout);
- stopOptionsProcessing();
- _helpRequested = true;
- }
-
- int main(const std::vector<std::string>& args)
- {
- if (!_helpRequested)
- {
- unsigned short port = (unsigned short)
- config().getInt("HTTPTimeServer.port", 9980);
- std::string format(
- config().getString("HTTPTimeServer.format",
- DateTimeFormat::SORTABLE_FORMAT));
-
- ServerSocket svs(port);
- HTTPServer srv(new TimeRequestHandlerFactory(format),
- svs, new HTTPServerParams);
- srv.start();
- waitForTerminationRequest();
- srv.stop();
- }
- return Application::EXIT_OK;
- }
-
-private:
- bool _helpRequested;
-};
-
-int main(int argc, char** argv)
-{
- HTTPTimeServer app;
- return app.run(argc, argv);
-} \ No newline at end of file