diff options
author | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2013-03-06 18:23:17 (GMT) |
---|---|---|
committer | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2013-03-06 18:23:17 (GMT) |
commit | e1a31a44c946d58a1b4654e5daa2d10d9c6f881d (patch) | |
tree | 7ce434b9bfb30c2de74cfe1f226c2ceda4ee8178 /src/uscxml/server | |
parent | 8c4977361f9e7998da298b9648f3ad4be5e772ff (diff) | |
download | uscxml-e1a31a44c946d58a1b4654e5daa2d10d9c6f881d.zip uscxml-e1a31a44c946d58a1b4654e5daa2d10d9c6f881d.tar.gz uscxml-e1a31a44c946d58a1b4654e5daa2d10d9c6f881d.tar.bz2 |
Changed directory monitor to polling behaviour :(
Diffstat (limited to 'src/uscxml/server')
-rw-r--r-- | src/uscxml/server/HTTPServer.cpp | 62 | ||||
-rw-r--r-- | src/uscxml/server/HTTPServer.h | 4 |
2 files changed, 36 insertions, 30 deletions
diff --git a/src/uscxml/server/HTTPServer.cpp b/src/uscxml/server/HTTPServer.cpp index a7957ea..ebc5b91 100644 --- a/src/uscxml/server/HTTPServer.cpp +++ b/src/uscxml/server/HTTPServer.cpp @@ -33,9 +33,9 @@ #endif namespace uscxml { - + HTTPServer::HTTPServer(unsigned short port) { - _port = port; + _port = port; _base = event_base_new(); _http = evhttp_new(_base); _handle = NULL; @@ -58,24 +58,25 @@ std::map<std::string, std::string> HTTPServer::mimeTypes; HTTPServer* HTTPServer::getInstance(int port) { tthread::lock_guard<tthread::recursive_mutex> lock(_instanceMutex); if (_instance == NULL) { - - // this is but a tiny list, supply a content-type <header> yourself - mimeTypes["txt"] = "text/plain"; - mimeTypes["c"] = "text/plain"; - mimeTypes["h"] = "text/plain"; - mimeTypes["html"] = "text/html"; - mimeTypes["htm"] = "text/htm"; - mimeTypes["css"] = "text/css"; - mimeTypes["gif"] = "image/gif"; - mimeTypes["jpg"] = "image/jpeg"; - mimeTypes["jpeg"] = "image/jpeg"; - mimeTypes["mpg"] = "video/mpeg"; - mimeTypes["mov"] = "video/quicktime"; - mimeTypes["png"] = "image/png"; - mimeTypes["pdf"] = "application/pdf"; - mimeTypes["ps"] = "application/postscript"; - mimeTypes["tif"] = "image/tiff"; - mimeTypes["tiff"] = "image/tiff"; + + // this is but a tiny list, supply a content-type <header> yourself + mimeTypes["txt"] = "text/plain"; + mimeTypes["c"] = "text/plain"; + mimeTypes["h"] = "text/plain"; + mimeTypes["html"] = "text/html"; + mimeTypes["htm"] = "text/htm"; + mimeTypes["css"] = "text/css"; + mimeTypes["bmp"] = "image/bmp"; + mimeTypes["gif"] = "image/gif"; + mimeTypes["jpg"] = "image/jpeg"; + mimeTypes["jpeg"] = "image/jpeg"; + mimeTypes["mpg"] = "video/mpeg"; + mimeTypes["mov"] = "video/quicktime"; + mimeTypes["png"] = "image/png"; + mimeTypes["pdf"] = "application/pdf"; + mimeTypes["ps"] = "application/postscript"; + mimeTypes["tif"] = "image/tiff"; + mimeTypes["tiff"] = "image/tiff"; #ifndef _WIN32 evthread_use_pthreads(); @@ -89,9 +90,9 @@ HTTPServer* HTTPServer::getInstance(int port) { } std::string HTTPServer::mimeTypeForExtension(const std::string& ext) { - if (mimeTypes.find(ext) != mimeTypes.end()) - return mimeTypes[ext]; - return ""; + if (mimeTypes.find(ext) != mimeTypes.end()) + return mimeTypes[ext]; + return ""; } void HTTPServer::httpRecvReqCallback(struct evhttp_request *req, void *callbackData) { @@ -220,18 +221,23 @@ void HTTPServer::processByMatchingServlet(const Request& request) { } void HTTPServer::reply(const Reply& reply) { - struct evbuffer *evb = evbuffer_new(); + if (reply.content.size() > 0 && reply.headers.find("Content-Type") == reply.headers.end()) { + LOG(INFO) << "Sending content without Content-Type header"; + } - if (reply.content.size() > 0 && reply.headers.find("Content-Type") == reply.headers.end()) { - LOG(INFO) << "Sending content without Content-Type header"; - } - std::map<std::string, std::string>::const_iterator headerIter = reply.headers.begin(); while(headerIter != reply.headers.end()) { evhttp_add_header(evhttp_request_get_output_headers(reply.curlReq), headerIter->first.c_str(), headerIter->second.c_str()); headerIter++; } + if (reply.status >= 400) { + evhttp_send_error(reply.curlReq, reply.status, NULL); + return; + } + + struct evbuffer *evb = evbuffer_new(); + if (!boost::iequals(reply.type, "HEAD")) evbuffer_add(evb, reply.content.data(), reply.content.size()); diff --git a/src/uscxml/server/HTTPServer.h b/src/uscxml/server/HTTPServer.h index 9bab1a1..c573422 100644 --- a/src/uscxml/server/HTTPServer.h +++ b/src/uscxml/server/HTTPServer.h @@ -41,7 +41,7 @@ public: static std::string getBaseURL(); static void reply(const Reply& reply); - static std::string mimeTypeForExtension(const std::string& ext); + static std::string mimeTypeForExtension(const std::string& ext); static bool registerServlet(const std::string& path, HTTPServlet* servlet); ///< Register a servlet, returns false if path is already taken static void unregisterServlet(HTTPServlet* servlet); @@ -58,7 +58,7 @@ private: static void httpRecvReqCallback(struct evhttp_request *req, void *callbackData); void processByMatchingServlet(const Request& request); - static std::map<std::string, std::string> mimeTypes; + static std::map<std::string, std::string> mimeTypes; std::map<std::string, HTTPServlet*> _servlets; typedef std::map<std::string, HTTPServlet*>::iterator servlet_iter_t; |