C++ HTTP server

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
micro-httpd is a little too micro, and is C, not C++.
closed account (EzwRko23)
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
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
closed account (EzwRko23)
Apache Web Server cannot be embedded.
I can't and won't use Java because the rest of my app is written in C++.
http://www.boost.org/doc/libs/1_39_0/doc/html/boost_asio/examples.html

You will find three HTTP server examples there.
Tnx, PanGalactic.

Good enough.
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.
Try tntnet (http://www.tntnet.org/). And sorry for the duplicate post. I already suggested it in another thread.
Topic archived. No new replies allowed.