Sep 30, 2010 at 1:28am UTC
I'm searching my ass of for a C++-based HTTP server that just simply works and isn't very complex and is easy to setup.
I tried FastCGI, but I couldn't get either lighttpd or apache's mod_fcgi to work on my macbook. Besides, I would prefer an independent HTTP server.
I would like a library that could be used like something like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#include "httpserver.h"
int handleHttpRequest(HTTP::Request request)
{
std::string qs = request->getQueryString();
request.setHeader("Content-Type" ,"text/plain" );
request.sendHeaders(200);
request << "Hi there, you requested " << qs << "!\r\n" ;
request.end();
}
int main(...)
{
HTTP::Server server();
server.bind(80);
while (true ) {
HTTP::Request request = server.accept();
handleHttpRequest(request);
}
return 0;
}
The server doesn't need to support multi-threading; I can handle that myself. Build-in multi-threading could be nice though.
It must be able to be compiled and run on Mac OS X and CentOS. Windows-support isn't a requirement.
Any recommendations?
Last edited on Sep 30, 2010 at 1:29am UTC
Sep 30, 2010 at 12:57pm UTC
micro-httpd is a little too micro, and is C, not C++.
Oct 1, 2010 at 9:26am UTC
Jetty can do this exactly as you wish. Ooops - Java, not C++, but anyway, Java is much better (safer, dependable) for the web. CGI is your grandma technology. Where did you get that requirement for it must be C++?
Last edited on Oct 1, 2010 at 9:27am UTC
Oct 1, 2010 at 9:29am UTC
How about the award winning Apache Web Server ? It may not be light any longer but it does prove it can handle high traffic load.
Please note I refer to the Apache HTTPD server and not the Apache Tomcat which is Java-based servlet container.
Edit: URL at
http://httpd.apache.org/
Last edited on Oct 1, 2010 at 9:31am UTC
Oct 1, 2010 at 10:25am UTC
Apache Web Server cannot be embedded.
Oct 1, 2010 at 10:44am UTC
I can't and won't use Java because the rest of my app is written in C++.
Oct 1, 2010 at 10:43pm UTC
Tnx, PanGalactic.
Good enough.
Oct 4, 2010 at 2:56am UTC
I forsee if there is enough demand for a C++ HTTP server, instead of just examples, the C++ folks at Boost can provide it as a common re-usable class isn't it ? That is, provide a new C++ class say called Boost::HTTPServer. This will make C++ more geared towards "business-centric" arena.