restbed icon indicating copy to clipboard operation
restbed copied to clipboard

content to long, got net::ERR_CONTENT_LENGTH_MISMATCH

Open T4lus opened this issue 8 years ago • 11 comments

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 28853977

and the browser console throw me this error : net::ERR_CONTENT_LENGTH_MISMATCH

should I use deflate to send data ?

T4lus avatar Feb 27 '17 08:02 T4lus

Please can you detail a working example so we may simulate your issue?

ben-crowhurst avatar Feb 27 '17 10:02 ben-crowhurst

Note: your content-length: 28853977 is stating you're sending 28.8 megabytes of data. Have you confirmed this value is correct?

ben-crowhurst avatar Feb 27 '17 10:02 ben-crowhurst

yes the content length is correct, I'm sending data in json format : here is my test code :

` #include "gc_api_server.h" #include #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

T4lus avatar Feb 27 '17 10:02 T4lus

Please provide a complete example that can be built.

ben-crowhurst avatar Mar 28 '17 09:03 ben-crowhurst

Any further traction on this matter?

ben-crowhurst avatar May 07 '17 03:05 ben-crowhurst

Closing due to inactivity. If you decide this is still an issue please reopen this ticket and provide an example that can be built.

ben-crowhurst avatar May 09 '17 10:05 ben-crowhurst

I'm having the same issue with large files

CheyenneForbes avatar May 21 '18 20:05 CheyenneForbes

@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?

ben-crowhurst avatar May 21 '18 20:05 ben-crowhurst

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 );
    }
}

CheyenneForbes avatar May 21 '18 20:05 CheyenneForbes

the bootstrap js and css files are loaded sometimes but fail other times with net::ERR_CONTENT_LENGTH_MISMATCH

CheyenneForbes avatar May 21 '18 20:05 CheyenneForbes

@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.

ben-crowhurst avatar Feb 09 '20 03:02 ben-crowhurst