Open T4lus opened 7 years ago
Please can you detail a working example so we may simulate your issue?
Note: your content-length: 28853977
is stating you're sending 28.8 megabytes of data. Have you confirmed this value is correct?
yes the content length is correct, I'm sending data in json format : here is my test code :
`
#include <restbed>
#include <json.hpp>
using namespace restbed;
using json = nlohmann::json;
void handler_get_bench(const std::shared_ptr< Session > session){
const auto& request = session->get_request();
json result;
Random *PRNG = new Random();
PRNG->setSeed((int)time(NULL));
result["param"] = request->get_path_parameter("nb");
result["seed"] = PRNG->getSeed();
for (int i = 0; i < std::stoi(request->get_path_parameter("nb")); i++)
result["rand"][std::to_string(i)] = PRNG->rand();
std::cout << result.dump(4) << std::endl;
session->close( OK, result.dump(4), { {"Content-Type", "application/json"}, {"Content-Length", std::to_string(result.dump(4).length())} });
}
int main(int argc, char* argv[])
{
auto benchRes = std::make_shared<Resource>();
benchRes->set_path( "/api/bench/{nb: .*}" );
benchRes->set_method_handler("GET", handler_get_bench);
auto settings = std::make_shared<Settings>();
settings->set_port(9080);
settings->set_worker_limit(4);
Service service;
service.publish(benchRes);
service.start(settings);
return EXIT_SUCCESS;
}`
the class Random
can be replace with any unix like PRNG, its' just a custom implementation for procedurale things
Please provide a complete example that can be built.
Any further traction on this matter?
Closing due to inactivity. If you decide this is still an issue please reopen this ticket and provide an example that can be built.
I'm having the same issue with large files
@CheyenneForbes What environmental setup do you have in place? Can you provide any additional information that might allow us to replicate this issue on our end?
void StaticHandler(const shared_ptr<Session>session){
auto request = session->get_request();
std::string filepath = request->get_path();
std::ifstream stream(filepath.data(), std::ifstream::in);
if ( stream.is_open( ) )
{
const std::string body = string( istreambuf_iterator< char >( stream ), istreambuf_iterator< char >( ) );
const std::multimap< string, string > headers
{
{ "Content-Type", ext_to_mime(filepath) },
{ "Content-Length", std::to_string( body.length( ) ) }
};
session->close( OK, body, headers );
}
else
{
session->close( NOT_FOUND );
}
}
the bootstrap js and css files are loaded sometimes but fail other times with net::ERR_CONTENT_LENGTH_MISMATCH
@CheyenneForbes / @T4lus I've just run a test using a 6.6MB and 8.9MB JPEG file with no failure detected.
Please can I request one of you provide a complete stripped-down example including the payload (file) you are using to replicate this issue?
What does the server code look like? What HTTP client are you using? What OS are you running on? What version of build tools are you using? What version, provide commit hash, of Restbed are you on? etc...
Keen to put this issue to bed in the 4.7 release branch.
Hi, I'm working on an heavy API (about procédurale galaxy generation)
For my benchmark I'm generating 1 000 000 of random number I get all my number in the server terminal, but the browser stop fectching the ressource around 16.2Mb for a
Content-Length
of 28853977and the browser console throw me this error :
net::ERR_CONTENT_LENGTH_MISMATCH
should I use deflate to send data ?