Skip to content

CROW_CATCHALL_ROUTE response is truncated #669

@cschreib

Description

@cschreib

Currently on the master branch (b516efe). I tried using CROW_CATCHALL_ROUTE to implement some custom routing logic myself. I cannot seem to get it to work; the resulting response always ends up empty. When I enable debug logs, I see that it encounters an error (the URL I requested was http://0.0.0.0:8001/):

(2023-06-25 13:45:02) [INFO    ] Crow/master server is running at http://0.0.0.0:8001 using 4 threads
(2023-06-25 13:45:02) [INFO    ] Call `app.loglevel(crow::LogLevel::Warning)` to hide Info level logs.
(2023-06-25 13:45:02) [DEBUG   ] 0x1eafdf0 {0} queue length: 1
(2023-06-25 13:45:03) [DEBUG   ] 0x1eca050 {1} queue length: 1
(2023-06-25 13:45:03) [DEBUG   ] 0x1ecac60 timer cancelled: 0x7fe194499610 0
(2023-06-25 13:45:03) [DEBUG   ] task_timer cancelled: 0x7fe194499610 0
(2023-06-25 13:45:03) [DEBUG   ] task_timer scheduled: 0x7fe194499610 1
(2023-06-25 13:45:03) [DEBUG   ] 0x1ecac60 timer added: 0x7fe194499610 1
(2023-06-25 13:45:03) [DEBUG   ] Cannot match rules /. 
(2023-06-25 13:45:03) [INFO    ] Response: 0x1ecac60 / 200 0
(2023-06-25 13:45:03) [DEBUG   ] 0x1ecac60 timer cancelled: 0x7fe194499610 1
(2023-06-25 13:45:03) [DEBUG   ] task_timer cancelled: 0x7fe194499610 1
(2023-06-25 13:45:03) [DEBUG   ] 0x1ecac60 from read(1) with description: "stream ended at an unexpected time"
(2023-06-25 13:45:03) [DEBUG   ] 0x1ecac60 from write(2)

Here's the curl request result:

$ curl -v http://0.0.0.0:8001/
*   Trying 0.0.0.0:8001...
* TCP_NODELAY set
* Connected to 0.0.0.0 (127.0.0.1) port 8001 (#0)
> GET / HTTP/1.1
> Host: 0.0.0.0:8001
> User-Agent: curl/7.68.0
> Accept: */*
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< X-Content-Type-Options: nosniff
< X-Frame-Options: DENY
< Strict-Transport-Security: max-age=63072000
* Connection #0 to host 0.0.0.0 left intact

Here's the code:

#include <crow.h>

int main() {
    crow::SimpleApp app;

    crow::logger::setLogLevel(crow::LogLevel::Debug);

    CROW_CATCHALL_ROUTE(app)
    ([](const crow::request& req) {
        crow::response res;
        res.add_header("Content-Type", "text/html");
        res.add_header("Access-Control-Allow-Origin", "*");
        res.add_header(
            "Content-Security-Policy", "script-src 'self' 'unsafe-eval' 'unsafe-inline'; "
                                       "default-src 'self' 'unsafe-inline' *.corentin.net");
        res.add_header("Strict-Transport-Security", "max-age=63072000");
        res.add_header("X-Frame-Options", "DENY");
        res.add_header("X-Content-Type-Options", "nosniff");
        res.body = "Not found";
        return res;
    });

    app.port(8001).multithreaded().run();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions