CrowCpp / Crow

A Fast and Easy to use microframework for the web.
https://crowcpp.org
Other
3.31k stars 365 forks source link

Large request messages - http routes #907

Open akjt opened 1 month ago

akjt commented 1 month ago

Is there a limit to the size of the request message.

When I run a

curl -x PUT url -H "Content-Type: application/json" -d "JsonMessage"

it seems that when the json message exceeds 1000 bytes I dont get any response back from my end point. In fact, it seems that problem happens somewhere deep inside the crow code, i.e., I dont reach to my callback url.

Curl just replies back with the following: curl: (52) Empty reply from server

Any help / hint would be much appreciated

@The-EDev

I discovered stream_threshold which is defaulted to around 1MiB, however , this seems to only apply for response body, not request bodies. Is there really no way I can extend the threshold to send larger request bodies

I now tried with debug log enabled and I got some more logs: - please note when reducing the json size I dont see the invalid http method error


(2024-10-02 20:34:02) [DEBUG   ] 0xffffac001160 {0} queue length: 2
Oct 02 20:34:02 ubuntu123 test_app[642467]: (2024-10-02 20:34:02) [DEBUG   ] 0xffffa8002530 timer cancelled: 0xffffb104afb0 0
Oct 02 20:34:02 ubuntu123 test_app[642467]: (2024-10-02 20:34:02) [DEBUG   ] task_timer cancelled: 0xffffb104afb0 0
Oct 02 20:34:02 ubuntu123 test_app[642467]: (2024-10-02 20:34:02) [DEBUG   ] task_timer scheduled: 0xffffb104afb0 1
Oct 02 20:34:02 ubuntu123 test_app[642467]: (2024-10-02 20:34:02) [DEBUG   ] 0xffffa8002530 timer added: 0xffffb104afb0 1
Oct 02 20:34:02 ubuntu123 test_app[642467]: (2024-10-02 20:34:02) [DEBUG   ] 0xffffa8002530 timer cancelled: 0xffffb104afb0 1
Oct 02 20:34:02 ubuntu123 test_app[642467]: (2024-10-02 20:34:02) [DEBUG   ] task_timer cancelled: 0xffffb104afb0 1
Oct 02 20:34:02 ubuntu123 test_app[642467]: (2024-10-02 20:34:02) [DEBUG   ] task_timer scheduled: 0xffffb104afb0 2
Oct 02 20:34:02 ubuntu123 test_app[642467]: (2024-10-02 20:34:02) [DEBUG   ] 0xffffa8002530 timer added: 0xffffb104afb0 2
Oct 02 20:34:02 ubuntu123 test_app[642467]: (2024-10-02 20:34:02) [DEBUG   ] 0xffffa8002530 timer cancelled: 0xffffb104afb0 2
Oct 02 20:34:02 ubuntu123 test_app[642467]: (2024-10-02 20:34:02) [DEBUG   ] task_timer cancelled: 0xffffb104afb0 2
Oct 02 20:34:02 ubuntu123 test_app[642467]: (2024-10-02 20:34:02) [DEBUG   ] 0xffffa8002530 from read(1) with description: "invalid HTTP method"
Oct 02 20:34:02 ubuntu123 test_app[642467]: (2024-10-02 20:34:02) [DEBUG   ] 0xffffa8002530 is_reading 0 is_writing 0
Oct 02 20:34:02 ubuntu123 test_app[642467]: (2024-10-02 20:34:02) [DEBUG   ] 0xffffa8002530 delete (idle) (queue length: 1)
Oct 02 20:34:02 ubuntu123 test_app[642467]: (2024-10-02 20:34:02) [DEBUG   ] 0xffffa8002530 timer cancelled: 0xffffb104afb0 2
Oct 02 20:34:02 ubuntu123 test_app[642467]: (2024-10-02 20:34:02) [DEBUG   ] task_timer cancelled: 0xffffb104afb0 2
Oct 02 20:34:02 ubuntu123 test_app[642467]: (2024-10-02 20:34:02) [DEBUG   ] 0xffffac001160 {0} queue length: 2
Oct 02 20:34:02 ubuntu123 test_app[642467]: (2024-10-02 20:34:02) [DEBUG   ] 0xffffa8002530 timer cancelled: 0xffffb104afb0 0
Oct 02 20:34:02 ubuntu123 test_app[642467]: (2024-10-02 20:34:02) [DEBUG   ] task_timer cancelled: 0xffffb104afb0 0
Oct 02 20:34:02 ubuntu123 test_app[642467]: (2024-10-02 20:34:02) [DEBUG   ] task_timer scheduled: 0xffffb104afb0 1
Oct 02 20:34:02 ubuntu123 test_app[642467]: (2024-10-02 20:34:02) [DEBUG   ] 0xffffa8002530 timer added: 0xffffb104afb0 1
Oct 02 20:34:02 ubuntu123 test_app[642467]: (2024-10-02 20:34:02) [DEBUG   ] 0xffffa8002530 timer cancelled: 0xffffb104afb0 1
Oct 02 20:34:02 ubuntu123 test_app[642467]: (2024-10-02 20:34:02) [DEBUG   ] task_timer cancelled: 0xffffb104afb0 1
Oct 02 20:34:02 ubuntu123 test_app[642467]: (2024-10-02 20:34:02) [DEBUG   ] task_timer scheduled: 0xffffb104afb0 2
Oct 02 20:34:02 ubuntu123 test_app[642467]: (2024-10-02 20:34:02) [DEBUG   ] 0xffffa8002530 timer added: 0xffffb104afb0 2
Oct 02 20:34:02 ubuntu123 test_app[642467]: (2024-10-02 20:34:02) [DEBUG   ] 0xffffa8002530 timer cancelled: 0xffffb104afb0 2
Oct 02 20:34:02 ubuntu123 test_app[642467]: (2024-10-02 20:34:02) [DEBUG   ] task_timer cancelled: 0xffffb104afb0 2
Oct 02 20:34:02 ubuntu123 test_app[642467]: (2024-10-02 20:34:02) [DEBUG   ] 0xffffa8002530 from read(1) with description: "invalid HTTP method"
Oct 02 20:34:02 ubuntu123 test_app[642467]: (2024-10-02 20:34:02) [DEBUG   ] 0xffffa8002530 is_reading 0 is_writing 0
Oct 02 20:34:02 ubuntu123 test_app[642467]: (2024-10-02 20:34:02) [DEBUG   ] 0xffffa8002530 delete (idle) (queue length: 1)
Oct 02 20:34:02 ubuntu123 test_app[642467]: (2024-10-02 20:34:02) [DEBUG   ] 0xffffa8002530 timer cancelled: 0xffffb104afb0 2
Oct 02 20:34:02 ubuntu123 test_app[642467]: (2024-10-02 20:34:02) [DEBUG   ] task_timer cancelled: 0xffffb104afb0 2
gittiver commented 1 month ago

Hi, would it be possible to show the source code? Its hard to say something without knowing what is expected.

akjt commented 1 month ago
    std::future<void >ff;
    crow::App<crow::CORSHandler> m_app;

    CROW_ROUTE(m_app, "/traff").methods(crow::HTTPMethod::PUT)(
                [](const crow::request& request, crow::response& response) {
                    std::cout << request.body << std::endl;
                     response.body = "Thanks!";
                     response.end();
                });

   ff = m_app.bindaddr("127.0.0.1")
    .port(5600).stream_threshold(6097152)
    .signal_clear().loglevel(crow::LogLevel::DEBUG)
    .run_async();
gittiver commented 1 month ago

The error would be thrown from the http parser if you send an invalid request method - or alternatively if something is wrong with the encoding of the request. As the request method is on the beginning of the request I would assume there is maybe something wrong with encoding of requests - maybe an overwrite on the client side? Look first of what is sent - maybe with wireshark to get sure that you see what is going over the wire.

akjt commented 1 month ago

By reducing the size of what I send below 1KB it seems to work though

gittiver commented 1 month ago

I can't see, what is sent over the wire. so for now I assume, an incorrect Method is sent if request size is above 1K. The request is encoded on a client not on server side.