Server
I have a Boost::Asio based http WebService, which asynchronously processes client connections and replies with a JSON content preceded by HTTP headers:
std::string response += "HTTP/1.0 200 OK\r\n";
response += "Content-Length: 2000\r\n";
response += "Content-Type: application/json\r\n";
response += "Connection: close\r\n";
response += "\r\n";
response += meassageBody;
where messageBody is a JSON structure of size not bigger than 500.
Each time - after the response is sent back to client - I call the sequence below to have (I believe) socket closed:
m_oSocket.shutdown(boost::asio::ip::tcp::socket::shutdown_both, ec);
m_oSocket.close();
Client
To test the server I wrote a small client application in Qt that asks the server for content and shows if any error has been returned.
If the server replies with the "Content-Length" value in http header:
hard-coded (to 2000 as in example above), then the Qt client shows Error code 2, which stands for "Connection closed";
set to a proper JSON data size (usually about 400-500), then the Qt client shows Error code 0, which stands for "Unknown error";
Questions:
Does sending improper "Content-Length" value in http header have such influence on the way how the connection is terminated?
I thought that closing the socket on server side could make the connection be seen as closed also on the client side. How to accomplish both at once: having the proper "Content-Lenght" value sent and a "Connection closed" status on client side?
Thanks