I have written the following code (reduced and modified to the essential parts for posting here) to implement a response to a uri path "show". I want to generate a response in the code and return it. I generated this response in many different ways, but the result is always the following error.
When I return a response string of length >=1000, the client either does not receive the payload or receives the first few characters. For all response strings of length < 1000, it has worked well. I tried to hard code the string, read it from a file, generate it programmatically etc. I tried to return as "text/plain", "application/json","text/html", but no help. It is possible that the magic number 1000 may be just a random coincidence, but it was consistent in over 30 tests I did. When I tried to do the same long responses (>1000) by modifying the example code given in "ph_test.cpp", and it has no such problem. What am I doing wrong?
struct DataHandler : CrackedUriPageHandler {
DataHandler(){}; //my code has one argument for the constructor, which is irrelevant here
virtual std::shared_ptr<Response> handle(const CrackedUri &uri,
const Request &request) override {
std::string resp = "";
for(int i=0; i< 999; i++) { // <= 999 is OK, but >=1000 is giving the error
resp += "m";
}
return Response::textResponse(resp);
};
};
//server starting code
auto root = make_shared<RootPageHandler>();
auto pathHandler = make_shared<PathHandler>("show", make_shared<DataHandler>());
root->add(pathHandler);
server.addPageHandler(root);
server.serve(server_root.data(), server_port); //server_root and server port come from elsewhere
The response is like (where the length 1020 is correct, but the content is missing after one char):
200 OK
Server: Seasocks/unversioned
Date: Tue, 19 Apr 2016 01:58:52 GMT
Access-Control-Allow-Origin: *
Content-Length: 1,020
Content-Type: text/plain
Connection: keep-alive
Last-Modified: Tue, 19 Apr 2016 01:58:52 GMT
Pragma: no-cache
Cache-Control: no-store
Expires: Tue, 19 Apr 2016 01:58:52 GMT
m
Compiler info: gcc 4.8.5 20150623 (Red Hat 4.8.5-4)
CMake options: ADD_DEFINITIONS(-Wall -Wextra -pedantic -ggdb3 -fPIC)
bug