In my search for a clean, simple, modern and cross-platform HTTP server, I settled on the example of the Boost.Asio C ++ 11 HTTP server. You can find it here and in the acceleration source directory boost_1_55_0/doc/html/boost_asio/example/cpp11/http/server.
I reviewed the code a bit and it looks pretty clean and very well documented, so it is almost perfect. I have only a few small questions that probably only affect performance, which is currently a secondary priority (primary stability), since I intend to use the same portable code on mobile and embedded platforms.
This magic number 512appears in request_handler::handle_request()at request_handler.cpp:
rep.status = reply::ok;
char buf[512];
while (is.read(buf, sizeof(buf)).gcount() > 0)
rep.content.append(buf, is.gcount());
rep.headers.resize(2);
rep.headers[0].name = "Content-Length";
rep.headers[0].value = std::to_string(rep.content.size());
rep.headers[1].name = "Content-Type";
rep.headers[1].value = mime_types::extension_to_type(extension);
connection.hpp connection :
std::array<char, 8192> buffer_;
, , 512 8 . , , , std::string 512 . , 4K 8K .
8K buffer_, , -, , . , . , 8K . ( ... 64K.), , 8K.