eidheim / Simple-Web-Server

A very simple, fast, multithreaded, platform independent HTTP and HTTPS server and client library implemented using C++11 and Boost.Asio. Created to be an easy way to make REST resources available from C++ applications.
MIT License
2.61k stars 751 forks source link

fix lost last chunk when there is two chunks in one read #170

Closed k1988 closed 6 years ago

k1988 commented 6 years ago

when i request some json files, the response sometimes with header "Transfer-Encoding: chunked"。 if the response is mini , the reqeust is block, the result is after readed one chunked, the rest bytes of chunked_streambuf is be discarded。

Test Enviroment:

Test code:

void testChunkJson() {
    // do emu
    HttpClient client("192.168.0.101:8080");

    // Synchronous request examples
    try {
        // decode gzip
        auto r2 = client.request("GET", "/test/chunk.json", "", SimpleWeb::CaseInsensitiveMultimap({ std::make_pair("Accept-Encoding","gzip, deflate") }));
        std::stringstream ss_decomp;
        boost::iostreams::filtering_istream in;
        in.push(boost::iostreams::gzip_decompressor());
        in.push(r2->content);
        boost::iostreams::copy(in, ss_decomp);
    }
    catch (const SimpleWeb::system_error &e) {
        cerr << "Client request error: " << e.what() << endl;
    }
}
eidheim commented 6 years ago

Thank you for reporting this and fixing the problem. I also cleaned up this function in https://github.com/eidheim/Simple-Web-Server/commit/af90d7598ffb0f15f13ed6f94b273723442d760c. Hopefully, everything works as expected after the cleanup. Please let me know if it does not.

k1988 commented 6 years ago

Yes, everything works as expected !