Boost Asio sample HTTP Server - taking this example and making it “ready for production”,

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:

  // Fill out the reply to be sent to the client.
  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 :

/// Buffer for incoming data.
std::array<char, 8192> buffer_;

, , 512 8 . , , , std::string 512 . , 4K 8K .

8K buffer_, , -, , . , . , 8K . ( ... 64K.), , 8K.

+3
3

512- , , . , , , . , , .

, ( ), , .

, , , chunk , .

HTTP- , 8k , .

, . http-, , . , , .

+2

@Torsten Robitzki, .

, , HTTP- . HTTP-, asio, . : via-httplib

, , .;)

+1

Apache nginx 8 (nginx 4 ). :

An increase from 4 KB to 8 KB would be due to the fact that cookies are getting bigger and bigger. But some kind of limit is a good idea to prevent communication with evil or broken customers. Make sure you send back the 4xx error if the client sends too large a request.

0
source

All Articles