c++ - Boost Asio sample HTTP Server -- taking this example and making it "production ready" -


In my search for a clean, simple, modern, and cross-platform HTTP server, I settled on Boost. ASIO C ++ 11 Example HTTP Server You can find it, and boost source source directory in boost_1_55_0 / doc / html / boost_asio / example / cpp11 / http / server

I have reviewed the code, and it starts getting quite clean and well documented, so it's almost ideal. I only have a few small questions, whose performance has only one effect, which is now a secondary priority (priority is stability), because I want to use the same portable code on mobile and embedded platforms

This magic number appears in 512 request_handler :: handle_request () in request_handler.cpp :

  // Fill in the reply to the customer. Rep.status = Answer: OK; Four buff [512]; While (Read: buf, sizeof (buf)). Gcount ()> 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);   

and connection.hpp in the connection class it is a member :

  // for incoming data / buffer Std :: array & lt; char, 8192 & gt; buffer_;   

I'm not sure Why these sizes, 512 bytes and 8 bytes are used. This is very clear to me The local file is being read and dump in response to std :: string 512 bytes at a time. I wonder if there will be more appropriate screening size of 4K or 8 .

For 8K buffer_ , it seems that it can be used to keep the data reaching the network, this is a bit difficult for me because I myself I am getting inside the courage of Aeso. I'm mainly worried about 8K which is not enough while a single packet will not exceed this length (I think ... though theoretical maximum packet size is 64K), I do not know why this is 8K needed.

512 bytes buffer is used to read data from file and then it was created Used to add to the body. This is definitely an unnecessary copy operation, but this is just one example. And it's definitely not optimal to copy the file into local storage and send it as a message.

This code is just an example and before you allow others to access your file system (even if it is using read only), you should really make sure that any confidential Information can not be read in this manner.

To handle large files, you probably want to use disk encoding and want to read and read part of the files by an overlap chuck of waiting for disk and network.

As always, HTTP requests, 8k I think enough, if requested bodies are handled otherwise.

But keep in mind, this is just an example if you want to create an HTTP server, whose purpose is to serve almost all possible purposes, you should look elsewhere. But do not expect that an implementation of this booth will be in the form of a trivial one.

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -