Corvusoft / restbed

Corvusoft's Restbed framework brings asynchronous RESTful functionality to C++14 applications.
http://www.corvusoft.co.uk
Other
1.93k stars 379 forks source link

content to long, got net::ERR_CONTENT_LENGTH_MISMATCH #189

Open T4lus opened 7 years ago

T4lus commented 7 years ago

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 ?

ben-crowhurst commented 7 years ago

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

ben-crowhurst commented 7 years ago

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

T4lus commented 7 years ago

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

`

include "gc_api_server.h"

#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

ben-crowhurst commented 7 years ago

Please provide a complete example that can be built.

ben-crowhurst commented 7 years ago

Any further traction on this matter?

ben-crowhurst commented 7 years ago

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

CheyenneForbes commented 6 years ago

I'm having the same issue with large files

ben-crowhurst commented 6 years ago

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

CheyenneForbes commented 6 years ago
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 commented 6 years ago

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

ben-crowhurst commented 4 years ago

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